Consider I have the following table structures for tables countries
, products
and suppliers
:
countries
------------------------
id
name
code
product
------------------------
id
name
price
suppliers
------------------------
id
name
A product
can be sold in different countries
but supplier
of that product
can be different. With that keeping in mind, I made a relations
table to keep track of which supplier
is delivering which product
in which country
:
relations
------------------------
country_id
product_id
supplier_id
Let's say I have a product A
which I need to store in country US
and CA
but the suppliers for these countries are X
and Y
respectively. The structure would look something like this:
countries
-------------------------------
id | name | code
-------------------------------
1 | United States | US
2 | Canada | CA
product
-------------------------------
id | name | price
-------------------------------
1 | A | 3.99
suppliers
------------
id | name
------------
1 | X
2 | Y
relations
-------------------------------
country_id | product_id | supplier_id
-------------------------------
1 | 1 | 1
2 | 1 | 2
My question is how can I use Eloquent Relationships to this table since many-to-many relationships only work on two tables. Is there any other workaround regarding this? Or is there any other efficient way to implement this scenario?
Thank you for your help.