我有如下表,其中是表role_id的外键,和是表的外键。rolesuser_idsetter_idusers
table 1:
+---------------------+
| users |
+---------------------+
| id |
| name |
| email |
| password |
+---------------------+
table 2:
+---------------------+
| roles |
+---------------------+
| id |
| name |
+---------------------+
pivot table:
+---------------------+
| role_user |
+---------------------+
| role_id |
| user_id |
| setter_id |
+---------------------+
我定义的模型:
用户型号:
class User extends Model
{
public $timestamps = false;
public function roles()
{
return $this->belongsToMany(Role::class);
}
}
好榜样:
class Role extends Model
{
public $timestamps = false;
public function users()
{
return $this->belongsToMany(User::class);
}
}
如何更改模型才能获得如下所示的数据?
user -> Roles -> setter :用户及其角色以及用户每个角色的setter
谢谢...
牛魔王的故事
holdtom