Question

Everytime I run php artisan routes, I get ReflectionException error and that UsersController class does not exist. I'm pretty sure it does.

I tried php composer dump-autoload and php artisan clear-compiled, they all give the same error.

This is my error log in /app/storage/logs/

[2014-03-30 01:41:24] production.ERROR: exception 'ReflectionException' with message 'Class UsersController does not exist' in C:\wamp\www\re3\vendor\laravel\framework\src\Illuminate\Routing\ControllerInspector.php:28
Stack trace:
#0 C:\wamp\www\re3\vendor\laravel\framework\src\Illuminate\Routing\ControllerInspector.php(28): ReflectionClass->__construct('UsersController')
#1 C:\wamp\www\re3\vendor\laravel\framework\src\Illuminate\Routing\Router.php(269): Illuminate\Routing\ControllerInspector->getRoutable('UsersController', 'users')
#2 C:\wamp\www\re3\vendor\laravel\framework\src\Illuminate\Support\Facades\Facade.php(211): Illuminate\Routing\Router->controller('users', 'UsersController')
#3 C:\wamp\www\re3\app\routes.php(14): Illuminate\Support\Facades\Facade::__callStatic('controller', Array)
#4 C:\wamp\www\re3\app\routes.php(14): Illuminate\Support\Facades\Route::controller('users', 'UsersController')
#5 C:\wamp\www\re3\vendor\laravel\framework\src\Illuminate\Foundation\start.php(269): require('C:\wamp\www\re3...')
#6 [internal function]: {closure}(Object(Illuminate\Foundation\Application))
#7 C:\wamp\www\re3\vendor\laravel\framework\src\Illuminate\Foundation\Application.php(792): call_user_func(Object(Closure), Object(Illuminate\Foundation\Application))
#8 C:\wamp\www\re3\vendor\laravel\framework\src\Illuminate\Foundation\Application.php(569): Illuminate\Foundation\Application->fireAppCallbacks(Array)
#9 C:\wamp\www\re3\vendor\laravel\framework\src\Illuminate\Foundation\Application.php(552): Illuminate\Foundation\Application->bootApplication()
#10 C:\wamp\www\re3\vendor\laravel\framework\src\Illuminate\Console\Application.php(44): Illuminate\Foundation\Application->boot()
#11 C:\wamp\www\re3\vendor\laravel\framework\src\Illuminate\Console\Application.php(33): Illuminate\Console\Application::make(Object(Illuminate\Foundation\Application))
#12 C:\wamp\www\re3\artisan(46): Illuminate\Console\Application::start(Object(Illuminate\Foundation\Application))
#13 {main} [] []
Was it helpful?

Solution

Somehow Laravel is not being able to find your UsersController, run

composer dumpautoload

Then check the file vendor/composer/autoload_classmap.php, your UsersController has to be there, otherwise composer won't be able to autoload it and Laravel will not have access to it.

if you cannot find your controllers in int, you have to check:

1) Your composer.json file, the folder where your controllers are must be in:

"autoload": {
    "classmap": [
        "app/controllers",
                  ....
    ],

2) Check if your classes are correctly named.

3) If you are using a namespace:

class UsersController extends Controller { ... }

You must use the namespace in your references to it and, probably it would be better, in this case, to use PSR-4 (or even PSR-0) to autoload your classes.

4) Compare classes that you have in autoload_classmap.php with those that are not there. There must be a difference in naming or directory placement.

5) Check if your classes all start with

<?php 

and not just

<?

This may not make too much difference for composer nor PHP, but it does for Laravel.

OTHER TIPS

In the controller file check the namespace.

For example,

namespace App\Http\Controllers\home;

In the name space above the controller file should exist in the home folder. If it exists in the home folder and if I have not included home above it give an reflection error.

Simply put the name space should correspond the folder structure where the controller file is placed.

In my case it happens that I had two controllers with the same name but in different locations:

app\Http\Controllers\Auth\PasswordController.php

and

app\Http\Controllers\Admin\Auth\PasswordController.php

The last one

app\Http\Controllers\Admin\Auth\PasswordController.php

had a wrong namespace (namespace App\Http\Controllers\Auth; instead of **namespace App\Http\Controllers\Admin\Auth;*) and because of this I constantly get the ReflectionException exception

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top