Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ReflectionException error on php artisan routes

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} [] []
like image 606
Halnex Avatar asked Oct 31 '25 16:10

Halnex


2 Answers

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.

like image 78
Antonio Carlos Ribeiro Avatar answered Nov 02 '25 11:11

Antonio Carlos Ribeiro


Same Issue happend with me. I just forgot to put request library into controller header. just put below line to your controller's use statement.

use Illuminate\Http\Request;

this is work in my case.

like image 38
prakash dantani Avatar answered Nov 02 '25 09:11

prakash dantani



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!