Support the ongoing development of Laravel.io →
Database Eloquent
Last updated 2 years ago.
0

Looks like what you want is a many-to-many relationship. An invoice has many products. A product has many invoices. In order to achieve that, you need something called the "pivot" table, which is the middle table that you created.

Docs: http://laravel.com/docs/5.1/eloquent-relationships#inserting-many-to-many-relationships

In this case, Laravel expects the pivot table to have the id, invoice_id, and product_id columns. However, since you also have an extra column for quantity, you need to tell Laravel about that. The docs do a good job of explaining it. Also, since it looks like you're already subscribed to Jeffrey, you can also watch his video on many-to-many relationships. :)

https://laracasts.com/lessons/many-to-many-relationships

0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.