5

I'm using Laravel v4.2 and getting the following error:

Class UserController does not exist

Here is my code:

user.php

class UserController extends BaseController {

    public function index(){
        return View::make('/')->with('title', 'Home | Public Review');
    }
}

routes.php

Route::get( '/', array(
    'as' => 'index',
    'uses' => 'UserController@index'
) );

How do I resolve this error?

dayuloli
  • 16,205
  • 16
  • 71
  • 126
PandaUser
  • 83
  • 2
  • 2
  • 7
  • `php artisan dump-autoload`? Is your controller in `app/controllers/`? What if you name the file `app/controllers/UserController.php` (instead of `user.php`)? – bishop Jul 09 '14 at 01:22
  • Thanks @bishop. I changed my user.php to UserController.php and it's working now. :) – PandaUser Jul 09 '14 at 01:42

2 Answers2

11

Typically, in Laravel 4, you'll find class UserController residing in app/controllers/UserController.php.

Laravel doesn't actually care, so long as the class in your routes.php can be auto-loaded. Consequently, always consider running php artisan dump-autoload after class name or class file name changes to ensure the autoloader is updated.

bishop
  • 37,830
  • 11
  • 104
  • 139
  • I have same issue. As per your suggestion I tried to run php artisan command, but getting error also on that which is ' "dump-autoload" is not defined.' I'm using laravel 5.0 – Mrugesh Tank Mar 08 '15 at 11:44
  • 1
    it's "composer dump-autoload" and not "php artisan dump-autoload" – Alucard Apr 21 '15 at 17:03
  • @Alucard: That also works: `artisan dump-autoload` is a super-set of `composer dump-autoload` (or locally `php composer.phar dump-autoload`). – bishop Apr 21 '15 at 18:58
-1

Is because the correct is composer dump-autoload