Laravel France

Relation belongsToMany

Avatar de SLITISabri
SLITISabri

Bonjour,

J'ai besoin d'extraire les informations en relation d'une table pivot (country_id et label_id). Comment faire svp ?

Table #1 (Bes)
    dateday, total, etc ...
Table #2 (Products)
    id, title, etc ...
Table #3 (bes_product)  Pivot
    bes_id, product_id, **country_id**, **label_id**, total, etc ...

Modèle #1 Product.php

public function products(){
        return $this->belongsToMany(Product::class)
            ->withPivot(['country_id', 'label_id', 'price']);
    }

Modèle #2 Bes.php

public function Bes() {
        return $this->belongsToMany(Bes::class);
}
Posté il y a 9 mois
Avatar de FrédéricAmary
FrédéricAmary

Salut, Inverse tes relations. Ta méthode bes() devrait être dans le model Product et ta méthode products() dans le model Bes.

Posté il y a 9 mois

Vous ne pouvez pas répondre à ce sujet.