Search code examples
phplaravellaravel-3

Use automatic controller routes in Laravel is a bad idea


I'm coming From CodeIgniter to Laravel.

So, is a bad idea using automatic routes to all of controllers?

Route::controller(Controller::detect());

Should I use this instead creating routes in routes.php?


Solution

  • Yes this is bad.

    Controller::detect() is actually not present in Laravel 4 because it is a bit broken.

    detect() will go through your filesystem and return controller files, but this is a bad idea because the order you define your routes matters. If you have any nested controllers you will find this breaking very easily.

    detect() will also return files in a different order depending on the file system, so this leads to a lot of unpredictability.

    I would argue that you should define all your routes any ways, it is a lot easier to read and debug.