【问题标题】:Multiple scoping resource route多范围资源路由
【发布时间】:2022-01-17 19:17:06
【问题描述】:

我正在创建路由资源,我使用 {post:slug} 进行路由模型绑定,但在某些方法(例如更新方法)中,我想使用 {post:id} 进行路由模型绑定并保留其他方法使用 {帖子:蛞蝓}

如何实现?是否可以添加多个范围

这是我的代码

Route::resource('/dashboard/posts', DashboardPostController::class)->scoped(['post' => 'slug']);

【问题讨论】:

    标签: laravel laravel-8


    【解决方案1】:

    首先,你需要使用不更新的资源:

    Route::resource('/dashboard/posts', DashboardPostController::class)->scoped(['post', 'slug'])->except('update');
    

    然后:

    Route::put('dashboard/posts/{posts:id}, [ DashboardPostController::class => 'update');
    

    【讨论】:

      猜你喜欢
      • 2014-09-25
      • 1970-01-01
      • 1970-01-01
      • 2020-11-18
      • 2011-09-19
      • 2011-08-20
      • 1970-01-01
      • 2013-01-31
      • 1970-01-01
      相关资源
      最近更新 更多