Hello I do have a ER diagram like below. I am thinking this is a hasmanyThrough relationship but I am not sure:
Any ideas how to define migrations and relationships for those tables ?
in User::class you can use the relation
public function organizations(){
return $this->belongsToMany(
Organization::class ,
'organization_user',
'user_id', //user key on intermediate table
'organization_id' //organization key on intermediate table
);
}
public function roles(){
return $this->belongsToMany(
Role::class ,
'organization_user',
'user_id', //user key on intermediate table
'role_id' //role key on intermediate table
);
}
more info on laravel many-to-many