我正在尝试将管理部分的所有路由分组以访问模型资源。到目前为止,我已经来了:
Route::group(['middleware' => 'auth', 'prefix' => 'admin', 'as' => 'admin::'], function() {
Route::get('dashboard', ['as' => 'dashboard', function() {
return view('pages.dashboard');
}]);
Route::resource('user', 'UserController', ['as' => 'user']);
Route::resource('plan', 'PlanController', ['as' => 'plan']);
Route::resource('answer', 'AnswerController', ['as' => 'answer']);
Route::resource('question', 'QuestionController', ['as' => 'question']);
Route::resource('retailer', 'RetailerController', ['as' => 'retailer']);
Route::resource('restriction', 'RestrictionController', ['as' => 'restriction']);
});
我想通过调用它们的名称来命名这些路由以更容易的方式访问它们。然而,它打破并说“路由[admin :: user]未定义。”我想使用路由命名功能来使用route('admin :: user')。我遇到资源路径问题。仪表板可正常工作 - 路线('admin :: dashboard')
我从这篇文章中了解到命名资源路由应该有效(Laravel named route for resource controller)
答案 0 :(得分:2)
给予资源路由名称自动运行php artisan route:list
以列出路由:
Route::group(['middleware' => 'auth', 'prefix' => 'admin', 'as' => 'admin::'], function() {
Route::get('dashboard', ['as' => 'dashboard', function() {
return view('pages.dashboard');
}]);
Route::resource('user', 'UserController');
});