I want to get 2 things.
-
Allocated Departments to a user
-
Departments not allocated to the user
I have achived first one through hasMany() relationship in AllocatedDepartment Modelpublic function departments(){ return $this->hasMany(Department::class, 'id', 'department_id'); }
I am not understanding how to get departments which are not allocated to the user.
EDITED:
I think you didn’t get my question.
Let say I have user A and departments X Y Z
X is assigned to A
Now I want to get list of departments assigned to A Output = X
and get list of departments assigned to A Output = Y Z
2
Answers
I have did this and it worked...
I think you are looking for Many-To-Many Relationships and Querying Relationship Absence.
User model
Department model
Now,