Php 如何将3个表相互关联

Php 如何将3个表相互关联,php,mysql,laravel,Php,Mysql,Laravel,如何将业务与员工和所有者(用户表,但使用管理员/所有者/经理/员工等角色)以及分支机构关联 public function getIsAdminAttribute() { return $this->hasRole('administrator'); } public function getIsOwnerAttribute() { return $this->hasRole('owner'); } public function getIsManagerAttr

如何将
业务
与员工和所有者(用户表,但使用管理员/所有者/经理/员工等角色)以及
分支机构
关联

public function getIsAdminAttribute() {
    return $this->hasRole('administrator');
}

public function getIsOwnerAttribute() {
    return $this->hasRole('owner');
}

public function getIsManagerAttribute() {
    return $this->hasRole('manager');
}

public function getIsEmployeeAttribute() {
    return $this->hasRole('employee');
}
这样我就可以知道谁是企业主和所有员工。和相关分支机构

范围:

public function scopeAllAdministrators() {
    return $this->whereHas('roles', function ($query) {
        $query->where('name', 'administrator');
    });
}

public function scopeAllCustomers() {
    return $this->whereHas('roles', function ($query) {
        $query->where('name', 'customer')->withoutGlobalScopes();
    });
}

public function scopeOtherThanCustomers() {
    return $this->whereHas('roles', function ($query) {
        $query->where('name', '<>', 'customer');
    });
}

public function scopeAllEmployees() {
    return $this->whereHas('roles', function ($query) {
        $query->where('name', 'employee');
    });
}
公共函数scopeAllAdministrators(){
返回$this->whereHas('roles',function($query){
$query->where('name','administrator');
});
}
公共函数scopeAllCustomers(){
返回$this->whereHas('roles',function($query){
$query->where('name','customer')->不带GlobalScopes();
});
}
公共函数作用域非客户(){
返回$this->whereHas('roles',function($query){
$query->where('name','customer');
});
}
公共职能范围所有员工(){
返回$this->whereHas('roles',function($query){
$query->where('name','employee');
});
}
Mysql: