mercredi 26 septembre 2018

Laravel eloquent many to many with conditions

I have many to many relationships. Let's say I am using foo and bar

class Foo extends Model
{
    public function bars() 
    {
       return $this->belongsToMany(Bar::class);
    }
}

class Bar extends Model
{
    public function foos() 
    {
       return $this->belongsToMany(Foo::class);
    }
}

how to show only Foo that have Bar so Foo record that not associated with Bar will not be displayed?...



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire