jginorio
1 week ago

Create route to attach a Product model to Order model

Posted 1 week ago by jginorio

Background Information

I'm building an invoicing system...

I created:

  • Product Model with a restful ProductController
  • Order Model with a restful OrderController

Relationships:

  • Product belongToMany Order
  • Order belongToMany Product

My Goal:

From my orders/show.blade.php I want to be able to add more products to that specific order.

What I've Tried:

I created a form in the orders/show.blade.php view that hits this route below

Route::patch('orders/{order:code}/products/add', '[email protected]')->name('orders.products.add');

My Problem / Doubts:

Does this violate the Laravel Restful controller? Should I create another controller called OrderProductController? Is there a better way of accomplishing this?

Please sign in or create an account to participate in this conversation.