1

i have 3 tables

user

user_id
name_user
contacts
request_id

request_register

request_id
user_id
team_id

team

team_id
name_team

i want get list of user details who register to team with spesific id, example:

team with id 1

id_user name_user contacts team_id name_team
1 michael 1234 1 phoenix
2 john 1232 1 phoenix
3 cindy 1222 1 phoenix
Ihda Anwari
  • 25
  • 1
  • 7

1 Answers1

0

You can use whereHas() method provided by Laravel, but you have to specify the relationships needed to query using the method, probably like this:

$teamId = //retrieve the team id...;
$users = User::whereHas('request_register', function() (Builder $query) use ($teamId) {
   $query->where('team_id', $teamId);
})->get();

This will automatically make a join between users and request_register to get what you want to get.

felixbmmm
  • 362
  • 3
  • 13