i dont at all follow why you need from and to, surely each product has one or more translations. why does the direction matter?
Help needed with relationship logic between three tables
Hi all, I've been playing with Laravel for a week now and everything was going great until I hit a problem I can't figure out by myself. I'm working on a translation application and so I need to fetch 2 records based on different ID from another table. Let me explain my models first:
1.) ProductListTranslation
This is where all the translations are stored
Example table data:
id | product_id | language_id | name | description
[1,1,1,'Shirt','Quality shirt']
[2,1,2, 'Hemd' 'Qualitätshemd']
2.) Product This table holds all the basic product data (supplier_id, product number, weight, price)
Example table data:
product_id | supplier_id | sku | ean | weight
[1, 1, '545-060', '2494859483', '1.20']
[2, 1, '545-061', '224533454', '1.30']
[3, 2, 'EC-T114', '9874441223', '44.50']
3.) ProductTranslationRelationship Translation relationship between languages (German to English, Spanish to Russian etc..)
Example table data:
id | from | to | supplier_id
[1, 1, 2, 1]
(both from and to are language_ids, let's say 1 is English and 2 is German, so we're translating products from supplier_id = 1 from English to German based on the example)
Now, based on the tables above, when someone goes to the route example.com/relationship/1 I list all the products from the Product table based on the supplier_id (in this example the ID is 1). I have this part figured out.
But I can't seem to be able to figure out how to set up the relationship so I can access both the translations like so:
foreach($products as $product)
{
$product->from->name; //should return Quality shirt
$product->to->name; //Should return Qualitätshemd
}
Thank you for your time reading my post, I hope someone can help me.
Please or to participate in this conversation.