【发布时间】:2021-04-06 13:08:50
【问题描述】:
我有想按名称、前缀和中间件组合在一起的路由。出于某种原因,Route::group 函数的 'name' 选项没有正确地尾随名称。我的代码不正确,还是这是一个错误?下面是路由组定义。
Route::group(['name' => 'admin.', 'prefix' => 'admin',
'middleware' => 'admin'], function () {
Route::get('/', function () {
return 'the index page';
})->name('index');
Route::get('/another', function () {
return 'another page';
})->name('another');
});
然后我清除并缓存了路线。这是清单。
+--------+----------+------------------------+-----------------------------+------------------------------------------------------------------------+------------+
| Domain | Method | URI | Name | Action | Middleware |
+--------+----------+------------------------+-----------------------------+------------------------------------------------------------------------+------------+
| | GET|HEAD | admin | index | Closure | web |
| | | | | | admin |
| | GET|HEAD | admin/another | another | Closure | web |
| | | | | | admin |
我希望在名称中看到 admin.index、admin.another、...
但是,如果我使用 Route::name 函数,它将正常工作。
Route::name('admin.')->group(function () {
Route::prefix('admin')->group(function () {
Route::middleware('admin')->group(function () {
Route::get('/', function () {
return 'the index page';
})->name('index');
Route::get('/another', function () {
return 'another page';
})->name('another');
});
});
});
+--------+----------+------------------------+-----------------------------+------------------------------------------------------------------------+---------------+
| Domain | Method | URI | Name | Action | Middleware |
+--------+----------+------------------------+-----------------------------+------------------------------------------------------------------------+---------------+
| | GET|HEAD | admin | admin.index | Closure | web |
| | | | | | admin |
| | GET|HEAD | admin/another | admin.another | Closure | web |
| | | | | | administrator |
【问题讨论】: