繁体   English   中英

如何定义这种Laravel关系

[英]How to define this Laravel relationship

您好,我确实有如下所示的ER图。 我以为这是一个hasmanyThrough关系,但我不确定:

在此处输入图片说明

有什么想法如何定义这些表的迁移和关系?

在User :: class中,您可以使用关系

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
    );
}

关于laravel多对多的更多信息

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM