Laravel 6.0 php artisan route:list returns “Target class [App\Http\Controllers\SessionsController] does not exist.”

与世无争的帅哥 提交于 2020-07-18 05:16:46

问题


I am using Laravel 6.0 and I try to list all my routes with artisan route:list, but it fails and returns:

Illuminate\Contracts\Container\BindingResolutionException : Target class [App\Http\Controllers\SessionsController] does not exist.

at /home/vagrant/code/vendor/laravel/framework/src/Illuminate/Container/Container.php:806 802| 803| try { 804| $reflector = new ReflectionClass($concrete); 805| } catch (ReflectionException $e) {

806| throw new BindingResolutionException("Target class [$concrete] does not exist.", 0, $e); 807| } 808| 809| // If the type is not instantiable, the developer is attempting to resolve 810| // an abstract type such as an Interface or Abstract Class and there is

Exception trace:

1 Illuminate\Foundation\Console\RouteListCommand::Illuminate\Foundation\Console{closure}(Object(Illuminate\Routing\Route)) [internal]:0

2 ReflectionException::("Class App\Http\Controllers\SessionsController does not exist") /home/vagrant/code/vendor/laravel/framework/src/Illuminate/Container/Container.php:804

3 ReflectionClass::__construct("App\Http\Controllers\SessionsController") /home/vagrant/code/vendor/laravel/framework/src/Illuminate/Container/Container.php:804

Up to now I just have a very simple web.php routes file:

Route::get('/', function () {
    return view('index');
});


Route::prefix('app')->group(function () {
    // Registration routes
    Route::get('registration/create', 'RegistrationController@create')->name('app-registration-form');
});


// Templates
Route::get('templates/ubold/{any}', 'UboldController@index');

Any idea how I could debug this issue?

Many thanks in advance!


回答1:


Run this command

  php artisan config:cache 



回答2:


For those who have similar issue with Illuminate\Contracts\Container\BindingResolutionException : Target class [<className>] does not exist. message, this also could be helpful:

composer dump-autoload



回答3:


In my case same error occurred because of forward slash / but it should be backward slash \ in defining route,

it happens when you have controller in folder like as in my case controller was in api Folder, so always use backward slash \ while mentioning controller name.

see example:

Error-prone code:

Route::apiResource('categories', 'api/CategoryController');

Solution code:

Route::apiResource('categories', 'api\CategoryController');



回答4:


Alright i got similar problem, i was trying to be smart so i wrote this in my web.php

Route::group([
    'middleware'    => '', // Removing this made everything work
    'as'            => 'admin.',
    'prefix'        => 'admin',
    'namespace'     => 'Admin',
],function(){

});

All i had to do is just to remove all the unnecessary/unused option from group. That's all.




回答5:


In my case it was a matter of Linux's file name case sensitivity. For a file named IndexController, having Indexcontroller will work in windows but not in Linux




回答6:


try to correct your controller name

my route was

Route::get('/lien/{id}','liensControler@show');

and my controller was

class liensController extends Controller
{
  // all the methods of controller goes here.
}



回答7:


I did all these

1: php artisan config:cache

2: checked for controller name spellings.

3: composer dump-autoload

4: Just changed the forward / slash to backward \ in route.

4th one worked for me.




回答8:


I had this problem while leaving an empty middleware class in my middleware groups by mistake :

    /**
     * The application's route middleware groups.
     *
     * @var array
     */
    protected $middlewareGroups = [
        'web' => [
            Middleware\EncryptCookies::class,
            \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
            \Illuminate\Session\Middleware\StartSession::class,
            \Illuminate\View\Middleware\ShareErrorsFromSession::class,
            Middleware\VerifyCsrfToken::class,
            \Illuminate\Routing\Middleware\SubstituteBindings::class,
        ],

        'api' => [
            'throttle:100,1',
            'bindings',
            'localization',
            '' // Was empty by mistake
        ],
    ];



回答9:


replace-

Route::resource('/admin/UserOff','admin/UsersController');

with-

Route::resource('/admin/UserOff','admin\UsersController');

forward / with \



来源:https://stackoverflow.com/questions/57865517/laravel-6-0-php-artisan-routelist-returns-target-class-app-http-controllers-s

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!