I have two table: Clients, Employees
Clients structure:
id
company_name
address
email
phone
created_by_employee
Employees structure:
id
name
position
department_id
I want to get all clients who were added by employees of the same department as the logged user.
So if I am logged in, I would like to get a list of my clients (added by me) and clients added by other employees, but only from my department (department_id). I have a problem with constructing a query in Laravel using join.
How can I build a query?
2
Answers
Department Model
Employee Model
Client Model
Get clients who were added by an employee from the same department:
if you’re using different tables then do.
Your table
Others table
Client Model
Not adding department_id on clients table might a mistake, unless if it’s not
neccessary
For same table
You created_y to know who the client belongs to or who created the client