是否可以在路由组中使用具有不同命名空间的控制器?
Route::group(['prefix' => 'dashboard', 'namespace' => 'admin'], function () {
Route::get('/', ['namespace'=>'Controllers','uses'=>'SiteController@dashobard']);
Route::get('posts', 'PostsController@index');
});
答案 0 :(得分:0)
正如@TimLewis在评论中所提到的那样。
(假设SiteController
的完整命名空间为App\Http\Controllers
)以下内容应该有效:
Route::group(['prefix' => 'dashboard', 'namespace' => 'admin'], function () {
Route::get('/', '\App\Http\Controllers\SiteController@dashboard');
Route::get('posts', 'PostsController@index');
});
然而,将路线分开会更有意义:
Route::group(['prefix' => 'dashboard'], function () {
Route::get('/', 'SiteController@dashboard');
Route::group(['namespace' => 'admin'], function () {
Route::get('posts', 'PostsController@index');
});
});
希望这有帮助!