【发布时间】:2021-03-24 19:08:55
【问题描述】:
我有一个具有这种结构的路由组:
Route::prefix('admin/{w_id}')->middleware(['auth'])->as('weblog.')->group(function () {
Route::get('/dashboard', [HomePageController::class, 'index'])->name('dashboard');
Route::resource('/blogcategory', CategoryController::class);
});
在仪表板路由上,我在 url 中有 w_id,当我想将用户重定向到 blogcategory 路由(从任何地方)我应该在路由助手类中手动传递 w_id,我需要从当前链接全局设置一些东西。
例如当我使用这种方法时:
'route' => 'weblog.blogcategory.store'
我收到如下错误:
Missing required parameters for [Route: weblog.blogcategory.store]
我应该手动将 w_id 参数传递给所有路由助手,我需要从页面的当前 url 全局设置 w_id。 我正在为用户的博客开发完全独立的管理区域,并且所有 url 中都存在博客 ID。
【问题讨论】:
-
你的路线应该像这样
{{ route('weblog.blogcategory.store', ['w_id'=>1, 'something_else_id'=>'ok']) }} -
@bhucho 是的,我知道,但我需要从当前 url 全局设置它,我不能使用你的方法,因为我必须做很多次
-
所以你想要那个组的默认值 w_id
-
@bhucho 是的,但来自当前 url ( request()->w_id )。我不知道如何部署它。
标签: php laravel laravel-routing laravel-8