0

let say I've this route

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

The first example will call destroy function inside ProductController but the second example I dont know where to put deleteDiscount function whether in ProductController or DiscountController should I put the second example in ProductController? or DiscountController in destroy function? which is best practice?

Rimuru Tempest
  • 525
  • 1
  • 4
  • 10
  • 2
    take a look at @Devon answer https://stackoverflow.com/questions/60097352/api-restful-laravel-6-x-best-practice-for-many-to-many-relatioship – Aslam H Sep 16 '20 at 02:55

1 Answers1

1

I like to follow something like this in my projects:

// delete a product

DELETE products/{id} : ProductController -> destroy()

// delete a discount

DELETE discounts/{id} : DiscountController -> destroy()

// delete all discounts related to a product

DELETE products/{id}/discount : ProductDiscountController -> destroyAll()

// delete one discount related to a product

DELETE products/{id}/discount/{discount_id} : ProductDiscountController -> destroy()

Jonathan Martins
  • 734
  • 7
  • 24