Skip to content
Advertisement

Eloquent relation pivot table with table

I read the laravel documentation but I couldn’t understand very well. I have this structure on my database.

PriceTable – which contains info about the period of promotional prices and the default price.

Product – which contains info about products.

and PriceTable_Product – which contains the foreign keys of Product and PriceTable and the respective price.

Example:

JavaScript

And at the Order table I can have multiples products, so I want to know if it is possible to relation Order table, with the pivot table PriceTable_Product, because I need the information of which table belongs the price when the product was sold.

Advertisement

Answer

First of all you may define the relations between Product and PriceTable.

Product model (AppProduct.php)

JavaScript

PriceTable model (AppPriceTable.php)

JavaScript

If you created the relations then you can use:

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement