Laravel 8 淺層嵌套

2021-07-16 18:01 更新

通常,并不完全需要在 URI 中同時擁有父 ID 和子 ID ,因為子 ID 已經(jīng)是唯一的標(biāo)識符。當(dāng)使用唯一標(biāo)識符(如自動遞增的主鍵)來標(biāo)識 URI 中的模型時,可以選擇使用「淺嵌套」的方式定義路由:

Route::resource('photos.comments', CommentController::class)->shallow();

上面的路由定義方式會定義以下路由:

HTTP 方式 URI 行為 路由名稱
GET /photos/{photo}/comments index photos.comments.index
GET /photos/{photo}/comments/create create photos.comments.create
POST /photos/{photo}/comments store photos.comments.store
GET /comments/{comment} show comments.show
GET /comments/{comment}/edit edit comments.edit
PUT/PATCH /comments/{comment} update comments.update
DELETE /comments/{comment} destroy comments.destroy
以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號