Controller routing does not work in Laravel 4

I am trying to register my controllers in Laravel 4. In routes.php I have:

 Route::get("/"," HomeController@index "); Route::get("search"," SearchController@index "); 

Now the main 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, since the same message appeared.

+6
source share
2 answers

names are case sensitive in L4. And the method name should exactly match (e.g. getIndex, not index ()).

Also, since it uses composer packages, you will need to run: php composer dump-autoload to detect any new classes / controllers

+20
source

I had the same problem and dump-autoload did not resolve it.

I realized that my class file was not declared in the vendor / composer / autoload_classmap.php file generated by Composer.

I cleared the contents of the cache folder. On Linux, this folder is: ~ / .composer / cache and on Windows 7: C: \ Users \\ AppData \ Local \ Composer \ files If bootstrap / compiled.php is present, it should also be deleted or run: php artisan clear-compiled .

After that, I deleted composer.lock and the vendor folder and ran: installer install. This placed my class file in the autoload_classmap.php file, however a ReflectionException was still thrown ...

As a last attempt, I copied and renamed another controller from an existing project, and this solved the problem.

+2
source

All Articles