5 months ago

Where condition on one to many in laravel eloquent

Posted 5 months ago by engrlaravel

I have one table teams & other table team_members

 teams(id,title, created_by)

Team.php model has below function

 public function members()
     return $this->hasMany('App\TeamMember', 'team_id');

TeamMember.php model has below functions

 public function member()
    return $this->belongsTo('App\User');

 public function team()
    return $this->belongsTo('App\Team');

If i am login, i want to select all teams created_by me or teams i am member of.

In other words, Assume my id is 10, so select

1- teams.created_by = 10

2- team_members.user_id=10

how i can get this by laravel eloquent with one query?

Please sign in or create an account to participate in this conversation.