Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Routing to Controller fails in Laravel 4

Tags:

php

laravel

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.

like image 544
Matanya Avatar asked Jan 07 '13 17:01

Matanya


2 Answers

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

like image 164
BenG Avatar answered Oct 24 '22 05:10

BenG


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.

like image 21
eaykin Avatar answered Oct 24 '22 03:10

eaykin