Laravel新软件包找不到正确的控制器路径



使用 Laravel 5.6.39 我安装了一个名为 Mercurius Messenger 的软件包

这个包通过作曲家安装它的所有资产,所以我可以在/vendor/launcher/中查看它们

在他们的存储库中,他们有一个路由文件。

Route::group([
'as'         => 'mercurius.',
'namespace'  => 'LauncherMercuriusHttpControllers',
'middleware' => [
// 'Mercurius',
'web',
'auth',
],
], function () {
// Mercurius home
Route::get('/messages', ['as' => 'home', 'uses' => 'MessagesController@index']);
// User Profile
Route::get('/profile/refresh', 'ProfileController@refresh');
Route::get('/profile/notifications', 'ProfileController@notifications');
});

控制器的名称空间在上面添加:

LauncherMercuriusHttpControllers

当我尝试点击这些路由之一时,出现此错误:

"Class AppHttpControllersLauncherMercuriusHttpControllersMessagesController does not exist"

它显然是将命名空间添加到我的应用程序\Http\控制器的当前命名空间中,有没有办法解决这个问题?还是我必须将所有相关文件复制到我的项目中并整理它们应该去哪里?

您绝对不需要(或想要(将供应商文件复制到您的项目中。

最简单的选择可能是从路由组中删除namespace属性,并在定义路由时使用完整的命名空间。

Route::get('/messages', ['as' => 'home', 'uses' => 'LauncherMercuriusHttpControllersMessagesController@index']);
Route::get('/profile/refresh', 'LauncherMercuriusHttpControllersProfileController@refresh');
Route::get('/profile/notifications', 'LauncherMercuriusHttpControllersProfileController@notifications');

或者,您可以创建一个新的路由文件(例如,mercurius.php(并将其映射到RouteServiceProvider中.php具有正确的命名空间。

public function map()
{
// ... existing route groups
$this->mapMercuriusRoutes();
}
protected function mapMercuriusRoutes()
{
Route::middleware(['web','auth','Mercurius'])
->namespace('LauncherMercuriusHttpControllers')
->group(base_path('routes/mercurius.php'));
}

最新更新