php 目标类[Admin\AdminController]不存在

mwg9r5ms  于 2022-10-30  发布在  PHP
关注(0)|答案(2)|浏览(196)

我正在开发一个网站使用Laravel 8通过观看youtube教程,我遇到了一个错误消息,不知道如何解决它。我试图改变名称空间,但它没有工作。ERROR MESSAGE PICT
我的管理控制器. 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');
});

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

oknwwptz

oknwwptz1#

命名空间应为完整路径

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

请按以下方式更改

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

nr7wwzry2#

您必须在命名空间中包含整个路径,如下所示...

相关问题