mardi 30 juillet 2019

Eloquent Relationship without Pivot Model

I have 3 tables:

  1. customer: fields: id, name
  2. item: fields: id, name
  3. customer_items: fields: customer_id, item_id, qty

Customer and Item have their separate Models as we would expect.

Question: How would I relate these two(Customer and Item) without having a pivot model.

I want to directly get customer items using $customer->items instead of doing $customer->customerItem->items which I find unnecessary since I don't want to track customerItems & customer by item.

Also, I cannot directly use customer_items table for Item model as I might need to retrieve all items in its controller.



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2K2a1uU
via IFTTT

Aucun commentaire:

Enregistrer un commentaire