Sep 15, 2015
9
Level 5
Correct pivot relationship Laravel 4.2
i have 3 tables:
representatives - id, name
teams - id, name
representative_team - representative_id, team_id, leader:boolean
My Models:
class Representative extends \Eloquent {
public function team(){
return $this->belongsToMany('Team', 'representative_team')->withPivot('leader');
}
}
class Team extends \Eloquent {
public function representatives(){
return $this->belongsToMany('Representative')->withPivot('leader');
}
}
What I am trying to do is: if a representative is a leader, loop through and show members on his team. When I try this in view i get errors:
@if($represntative->team->leader)
guess i am stuck and the reason for asking for help. Thx!
Level 88
Please or to participate in this conversation.