Reputation: 6361
I have a teams table which has following structure :
id | manager_id | leader_id | member_id |
All of these three ids i.e manager_id leader_id and member_id are referring to id of employees table how do I set relationship because usually I do :
public function functionName()
{
return $this->hasOne('\App\Models\Employee', 'id', 'manager_id');
}
But not able to figure out in this case
Upvotes: 1
Views: 35
Reputation: 4387
Team
model methods
public function manager(){
return $this->belongsTo('\App\Models\Employee', 'manager_id', 'id');
}
public function leader(){
return $this->belongsTo('\App\Models\Employee', 'leader_id', 'id');
}
public function member(){
return $this->belongsTo('\App\Models\Employee', 'member_id', 'id');
}
Upvotes: 1