首页 > 解决方案 > 目标类 [Admin\AdminController] 不存在

问题描述

我正在通过观看 youtube 教程使用 Laravel 8 开发网站,但遇到错误消息,不知道如何解决。我试图更改命名空间,但没有奏效。 错误信息图片

我的 AdminController.php 代码

<?php 

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;

class AdminController extends Controller
{
   public function dashboard(){
       return view('admin.admin_dashboard');
   }
}

还有我的 web.php

<?php

use Illuminate\Support\Facades\Route;

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

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

Auth::routes();

Route::get('/home', [App\Http\Controllers\HomeController::class, 'index'])->name('home');

Route::prefix('/admin')-> namespace ('Admin')-> group (function(){
   //All the admin roles will be defined here
   Route::get('dashboard','AdminController@dashboard');
});

谁能帮我解决这个问题?谢谢。

标签: phpweblaravel-8

解决方案


您的命名空间应该是完整路径

Route::prefix('/admin')-> namespace ('Admin')-> group (function(){
  ...
});

请更改如下

Route::prefix('/admin')->namespace('App\\Http\\Controllers\\Admin')-> group (function(){
  ...
});

推荐阅读