I have two models: User, Category.
Each user can have one or more categories in table User_categories.
Also there is table User and Categories.
My relationship are:
User
public function categories(){
return $this->hasMany('App\Category');
}
Category
public function users(){
return $this->belongsToMany('App\User');
}
I try to get all categories of user throuth model Category:
User::where("id", $id)->with("country", "city", "categories")->first();
via Darama