Zosax Bu istediğiniz yolun hem avantajı hem de dezavantajı var. Her bir kayıt bir dile göre tutuluyor. Örneğin sitede 3 dil varsa ve bir sandalye satmak istiyorsanız aynı sandalyeden 3 tane eklemeniz lazım. Bu durumda bu 3 sandalye 1 sandalyenin 3 farklı dil içeriğine sahip versiyonu olmuyor; 3 farklı ürün oluyor. Bu kesinlikle eticaret sitelerinde istenen bir yapı değil. Bunun yerine bir tane kayıt olur, farklı dildeki içerik ise ayrı bir tabloda ya da jsonb bir alanda tutulur. Mesela
products (Product)
+----+--------+
| id | code |
+----+--------+
| 8 | PRD008 |
+----+--------+
product_translations (ProductTranslation)
+----+------------+--------+------------------+
| id | product_id | locale | name |
+----+------------+--------+------------------+
| 1 | 8 | tr | Deneme Ürün |
| 2 | 8 | en | Test Product |
| 3 | 8 | ru | Тестовый продукт |
+----+------------+--------+------------------+
app/Models/Product.php
public function translations(): HasMany
{
return $this->hasMany(ProductTranslation::class);
}
public function translation(): HasOne
{
return $this->hasOne(ProductTranslation::class)
->ofMany()
->where('locale', app()->getLocale());
}
$product = Product::find(8);
$product->translation->name; // Deneme Ürün
app()->setLocale('en');
$product->translation->name; // Test Product
app()->setLocale('ru');
$product->translation->name; // Тестовый продукт
gibi...