Illuminate \ Contracts \ Container \ BindingResolutionException:目标类[App \ Http \ Controllers \ Admin \ DashboardadController]不存在

时间:2019-12-16 12:18:33

标签: laravel laravel-6

我正在使用Laravel 6.0,并且尝试使用

列出我的所有路线
  

php artisan route:list

失败并返回:

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

  at D:\xampp\htdocs\myws\vendor\laravel\framework\src\Illuminate\Container\Container.php:805
    801| 
    802|         try {
    803|             $reflector = new ReflectionClass($concrete);
    804|         } catch (ReflectionException $e) {
  > 805|             throw new BindingResolutionException("Target class [$concrete] does not exist.", 0, $e);
    806|         }
    807| 
    808|         // If the type is not instantiable, the developer is attempting to resolve
    809|         // 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\Admin\DashboardadController does not exist")
      D:\xampp\htdocs\myws\vendor\laravel\framework\src\Illuminate\Container\Container.php:803

我的路线

Route::group([ 'as'=>'admin.', 'prefix'=>'admin', 'namespace'=> 'Admin', 'middleware' => ['auth','admin']],
    function(){
        Route::get('dashboard', 'DashboardadController@index')->name('dashboard');
    });

    Route::group([ 'as'=>'author.', 'prefix'=>'author', 'namespace'=> 'Author', 'middleware' => ['auth','author']],
    function(){
        Route::get('dashboard', 'DashboardauController@index')->name('dashboard');
    });

我的RouteServiceProvider

  

受保护的$ namespace ='App \ Http \ Controllers';

有什么主意我可以调试这个问题吗?

非常感谢!

2 个答案:

答案 0 :(得分:0)

您的错误是因为您删除了DashboardController或更改了它的名称空间,并且在其他地方导入了它,却忘记了删除它的用法或更正了它的名称空间

当您运行php artisan route:list时,它将对每个控制器执行一次,并且如果任何控制器中有错误,该命令将失败并引发异常,因此我认为最好的解决方案是在您的控制器中搜索并找到该控制器会导致此错误,或者如果您使用的是良好的IDE,他们通常具有find in path功能,可以搜索路径或整个项目中的给定文本

修改
还请使用此约定来确保您的名称空间正确
但不要忘记导入dashboardcontroller

Route::group([ 'as'=>'admin.', 'prefix'=>'admin', 'middleware' => ['auth','admin']], function(){
        Route::get('dashboard', [DashboardController::class, 'index'])->name('dashboard');
    });

    Route::group([ 'as'=>'author.', 'prefix'=>'author', 'middleware' => ['auth','author']], function(){
        Route::get('dashboard', [DashboardController::class, 'index'])->name('dashboard');
    });

答案 1 :(得分:0)

尝试一下:

Route::resource('post/', DashboardController::class);