Ich habe eine Frage mit Laravel Beziehung OneToMany. Meine Datenbank hat 2 Tabelle product und product_entry. Produkt wird Informationen haben, um den gleichen Preis zu wählen ... und product_entry hat Informationen über Infomation.Laravel - Wählen Kind, wo param
1 Produkt haben viele product_entry wird eine andere Sprache. Aber Seite nur 1 Sprache in der gleichen Zeit, so habe ich sowieso nur product_entry haben product_entry_language gleiche aktuelle Sprache?
Beispiel: Ich habe 1 Produkt a mit Sprache "en" und "es". Die normale, aktuelle Sprache ist "en". In Klinge muss i produkt-> product_entries foreach und wenn (product_entry_language == "en") {** erhalten Info **} => Ich will nicht brauchen laufen foreach
Modell
class Product extends Model
{
use TransformableTrait;
protected $table = 'product';
protected $fillable = ['product_code','product_id'];
public function entries()
{
return $this->hasMany('App\Entities\ProductEntry', 'product_entry_product_id', 'product_id');
}
}
class ProductEntry extends Model
{
use TransformableTrait;
protected $table = 'product_entry';
protected $fillable = ['product_entry_product_id','product_entry_name'];
}
bitte posten zu Ihren Modellen. –
Ich hatte Model hinzugefügt –