Khan Shahrukh
Khan Shahrukh

Reputation: 6361

Multiple Ids of table A referring to Table B how to set relationship?

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

Answers (1)

Parvez Rahaman
Parvez Rahaman

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

Related Questions