php - 目标类 [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');
});
谁能帮我解决这个问题?谢谢。
解决方案
您的命名空间应该是完整路径
Route::prefix('/admin')-> namespace ('Admin')-> group (function(){
...
});
请更改如下
Route::prefix('/admin')->namespace('App\\Http\\Controllers\\Admin')-> group (function(){
...
});
推荐阅读
- function - 如何在泛型函数中构造具体类型?
- ejb - 从 pojo class==>org.jboss.remote-naming 访问 EJB
- javascript - 为什么我在尝试使用 ExpressJS 和 ReactJS 执行 Google 登录时不断收到 CORS 错误?
- python - Bitmex 样本做市商 [SSL: CERTIFICATE_VERIFY_FAILED]
- java - 如何在 Spring Boot 中从 swagger 中删除 Authentication 参数?
- javascript - Vue js watcher 对更改没有反应
- robotframework - 如何使用机器人框架上传文件?
- ios - 在调用 viewDidDisappear 之后修改视图是不好的做法吗?
- c++ - OPENCL 警告:不兼容的指针类型将 'float __global[16]' 传递给 '__global float4 * 类型的参数
- kotlin - 等价于 if(root == null) return root; 在科特林