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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.