【问题标题】:Laravel : ReflectionException Class App\Http\Controllers\DashboardController does not existLaravel:ReflectionException 类 App\Http\Controllers\DashboardController 不存在
【发布时间】:2021-01-21 12:35:45
【问题描述】:

登录到我的管理仪表板后,我收到以下错误:

ReflectionException 类 App\Http\Controllers\DashboardController 不存在

下面是我的DashboardController里面:public_html/app/Http/Controllers/Dashboard

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class DashboardController extends Controller
{
    public function index()
    {
        return view('dashboard.index');
    }
}

路由文件:

Auth::routes();
Route::get('logout', function () {
    \Illuminate\Support\Facades\Auth::logout();

    return redirect('/');
});


Route::get('/', 'HomeController@index')->name('home');
//Route::get('/about', 'AboutController@index')->name('about');
Route::get('/events', 'EventController@index')->name('events');
Route::get('/events/{event}', 'EventController@show')->name('events.show');
Route::get('/publications', 'PublicationController@index')->name('publications');
Route::get('/publications/{publication}', 'PublicationController@show')->name('publications.show');

Route::middleware(['web', 'auth'])->group(function () {

    Route::get('search/', 'SearchController@index')->name('search');

});

Route::middleware(['auth', 'dashboard'])->group(function () {
    Route::get('/dashboard', 'DashboardController@index')->name('dashboard.index');
    Route::resource('/dashboard/users/trashed', 'UserTrashedController', ['as' => 'dashboard.users']);
    Route::resource('/dashboard/users', 'UserController', ['as' => 'dashboard']);
    Route::resource('/dashboard/categories/trashed', 'CategoryTrashedController', ['as' => 'dashboard.categories']);
    Route::resource('/dashboard/categories', 'CategoryController', ['as' => 'dashboard']);
    Route::resource('/dashboard/events', 'Dashboard\EventController', ['as' => 'dashboard']);
    Route::resource('/dashboard/activity-logs', 'ActivityLogController', ['as' => 'dashboard']);
    Route::resource('/dashboard/pages', 'Dashboard\PageController', ['as' => 'dashboard']);
    Route::resource('/dashboard/publications', 'Dashboard\PublicationController', ['as' => 'dashboard']);
});

Route::any('/{any}', '\App\Http\Controllers\PageController@show')->where('any', '.*')->name('pages.show');

下面是我的 laravel 版本

Laravel 版本:5.8

我已经花了几个小时,但无法找到问题,有人可以帮我解决问题

【问题讨论】:

  • Welcome to SO .... 您能否调整DashboardController 中定义的命名空间以镜像文件夹结构,并添加Dashboard 部分?
  • 感谢@lagbox 的回复,我也试过了 namespace App\Http\Controllers\Dashboard;没用,你能告诉我这是不是你的意思吗

标签: php laravel laravel-5


【解决方案1】:

您在路由中引用的控制器以App\Http\Controllers 命名空间为前缀。由于您的 Controller 位于 this 的子命名空间中(也是此命名空间的映射目录的子文件夹),您需要将命名空间的其余部分告诉路由器到此 Controller:

Route::get('/dashboard', 'Dashboard\DashboardController@index')...

您还必须调整 DashboardController.php 文件中定义的命名空间:

namespace App\Http\Controllers\Dashboard;

【讨论】:

    猜你喜欢
    • 2019-01-01
    • 1970-01-01
    • 2017-12-23
    • 2020-05-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-05
    • 2016-09-16
    • 2020-01-07
    相关资源
    最近更新 更多