Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
174 views
in Technique[技术] by (71.8m points)

php - How I can associate 3 tables with each other

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...