[英]Laravel Rest API route best practice
假設我有這條路線
DELETE products/{id}
DELETE products/{id}/discount
第一個示例將在ProductController
調用destroy
函數,但第二個示例我不知道將deleteDiscount
函數放在哪里,無論是在ProductController
還是DiscountController
,我應該將第二個示例放在ProductController
嗎? 或DiscountController
在destroy
函數中? 這是最佳實踐?
我喜歡在我的項目中遵循這樣的事情:
// 刪除一個產品
DELETE products/{id}
: ProductController -> destroy()
// 刪除折扣
DELETE discounts/{id}
: DiscountController -> destroy()
// 刪除與產品相關的所有折扣
DELETE products/{id}/discount
: ProductDiscountController -> destroyAll()
// 刪除一個與產品相關的折扣
DELETE products/{id}/discount/{discount_id}
: ProductDiscountController -> destroy()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.