I'm trying to register my controllers in Laravel 4. In routes.php
I have:
Route::get("/","HomeController@index");
Route::get("search","SearchController@index");
Now, the home controller route is fine, but the search controller route gives me an error:
ReflectionException: Class SearchController does not exist
However, the class does exist. I even tried to create another sample controller, but to no avail, as the same message came up.
names are case sensitive in L4. And the method name should match exactly(e.g. getIndex, not index() ).
Also, because it uses composer packages, you will need to run:
php composer dump-autoload
to detect any new classes/controllers
I had the same problem and composer dump-autoload
did not resolve it.
I realized that my class file was not declared in vendor/composer/autoload_classmap.php generated by Composer.
I cleared the contents of the cache folder. In Linux, this folder is:
~/.composer/cache
and in Windows 7: C:\Users\\AppData\Local\Composer\files
If bootstrap/compiled.php is present, it should also be removed, or run: php artisan clear-compiled
.
After this, I removed composer.lock and the vendor folder and run: composer install. This put my class file into autoload_classmap.php however the ReflectionException was still being thrown...
As a final try, I copied and renamed another controller from the project that was already in use, and this resolved the problem.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With