mercredi 31 octobre 2018

Laravel relation Post and categories

I have a relationship between Post Model and Group Model (belongsToMany):

class Post extends Model
{
    public function category(){
        return $this->belongsToMany('App\Category');  
}

    public function groups(){

        return $this->belongsToMany('App\Group');
    }

}

And I have a relation between categories and post ^.

so when I create a group I choose a post for it and I want to show the post category in the table.

how I can use the categories in groups?

like $group->category()

Thanks



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire