多范围资源路由
Multiple scoping resource route
我正在创建路由资源,我使用 {post:slug} 进行路由模型绑定,但在某些方法(例如更新方法)中,我想使用 {post:id} 进行路由模型绑定并保留其他方法使用 {post:slug}
如何实现?是否可以添加多个范围
这是我的代码
Route::resource('/dashboard/posts', DashboardPostController::class)->scoped(['post' => 'slug']);
首先,您需要在不更新的情况下使用资源:
Route::resource('/dashboard/posts', DashboardPostController::class)->scoped(['post', 'slug'])->except('update');
然后:
Route::put('dashboard/posts/{posts:id}, [ DashboardPostController::class => 'update');
我正在创建路由资源,我使用 {post:slug} 进行路由模型绑定,但在某些方法(例如更新方法)中,我想使用 {post:id} 进行路由模型绑定并保留其他方法使用 {post:slug}
如何实现?是否可以添加多个范围
这是我的代码
Route::resource('/dashboard/posts', DashboardPostController::class)->scoped(['post' => 'slug']);
首先,您需要在不更新的情况下使用资源:
Route::resource('/dashboard/posts', DashboardPostController::class)->scoped(['post', 'slug'])->except('update');
然后:
Route::put('dashboard/posts/{posts:id}, [ DashboardPostController::class => 'update');