How I can associate business
with employees and owner (User table but using roles like Admin/Owner/Manager/Employee) and branches
?
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');
}
So I can know who is owner of business and all employees. And associated branches.
Scopes:
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');
});
}
Mysql: https://pastebin.com/uNFtfmmK
question from:
https://stackoverflow.com/questions/65599946/how-i-can-associate-3-tables-with-each-other 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…