Search code examples
laravellaravel-3

Laravel - Auto detecting Controllers


Pretty new to Laravel and I'm slightly confused to how routing works.

In FuelPHP I'm used to using file structure to define routes.

E.g. I have admin/clients/add and I would use a class of Admin_Clients (and a method action_add) for this and so on.

Using Controller::detect() registers the class admin.clients but when it comes to resolve it, it choses the Admin_Controller class unless I define every single route which I want to avoid.

If anyone could help me out it would be much appreciated.

Laravel vs 3.2


Solution

  • It's important to have a naming convention in Laravel, especially for controllers.

    In your case, renaming the Admin_Clients to AdminClients_Controller would probably be better idea.

    Then, I would restrain from using Controller::detect(), and explicitly create Route to each controller as following:

    Route::controller('AdminClients');
    

    From now, accessing of the AdminClients_Controller methods would work as following:

    http://localhost/controller/method/arguments
    

    For further explanation of how Routes work in Laravel, please refer to:

    http://laravel.com/docs/routing#the-basics