max
max

Reputation: 23

retriving data using relationship

I have two tables, employees & employee_manager.

employees : id,name

employee_manager : employee_id,manager_id

id of employees and employee_id of employee_manager are the same.

Both employee_id and manager_id are ids of employees from employees table.

The manager of a particular employee is found using manager_id. Now I want to view the name of the manager from employees table.

Upvotes: 1

Views: 47

Answers (1)

Sethu
Sethu

Reputation: 1379

please add this on your Employee model

public function manager()
{
    return $this->hasManyThrough('App\Models\Employee', 'App\Models\EmployeeManager', 'employee_id', 'id', 'id', 'manager_id'));
}

I hope this will solve your problem

Upvotes: 2

Related Questions