簡體   English   中英

Laravel Rest API 路由最佳實踐

[英]Laravel Rest API route best practice

假設我有這條路線

  1. DELETE products/{id}
  2. DELETE products/{id}/discount

第一個示例將在ProductController調用destroy函數,但第二個示例我不知道將deleteDiscount函數放在哪里,無論是在ProductController還是DiscountController ,我應該將第二個示例放在ProductController嗎? DiscountControllerdestroy函數中? 這是最佳實踐?

我喜歡在我的項目中遵循這樣的事情:

// 刪除一個產品

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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM