Tuesday, February 28, 2017

Get Model where relationship = id

Would love to know how other people are achieving the following?
Tables:
teams 
teams_users (pivot many teams, many users)
users

What i am trying to achieve
$teams->user->where('user_id', $id)->get();

however i am having to run a loop, and create another method on the team model to pluck(id, name)
    // foreach ($teams as $team) {
    //  # code...
    // dump($team->getUserIdsAttribute());
    // }

Do you know a better way?



via Harry Bosh

Advertisement