mardi 1 mars 2016

Laravel Retrieve related model through pivot table

So i'm a bit confused with this situation, I have the current relations: User hasmany Favourite favourites references to a Recipe model favourites is a pivot table but when I retrieve the favourites for a given user like:

$user->favourites

i get the favourite with the pivot data, but I want to get the fields of the recipe

Recipe.php:

public function favourites()
{
    return $this->hasMany('App\Favourite');
}

User.php:

public function favourites()
{
    return $this->hasMany('App\Favourite');
}

Favourite.php:

public function user()
{
    return $this->belongsTo('App\User','user_id');
}

public function recipes()
{
    return $this->belongsTo('App\Recipe','recipe_id');
}



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire