Reputation: 23
I have table USERS which has relations with JOBS and DESIGNATIONS and JOBS relations with DESIGNATION. If user logged in he can only see the assigned JOBS based on his designation. Please see below code.
TABLE STRUCTURES
job_user
id | user_id | job_id
designation_user
id | user_id | designation_id
designation_job
id | designation_id | job_id
USER MODEL
public function designations() {
return $this->belongsToMany(Designation::class, 'designation_user');
}
public function jobs() {
return $this->belongsToMany(Job::class, 'job_user');
}
JOB MODEL
public function designations() {
return $this->belongsToMany(Designation::class, 'job_designation');
}
public function users() {
return $this->belongsToMany(User::class, 'job_user');
}
DESIGNATION MODEL
public function users() {
return $this->belongsToMany(User::class, 'designation_user');
}
public function jobs() {
return $this->belongsToMany(Promo::class, 'job_designation');
}
What should be the query for this kind of situation. Thank you for the help.
Upvotes: 0
Views: 26