Skip to content
Advertisement

Laravel Eloquent version of “NOT IN” SQL

Just need the Eloquent ORM format of this query.. giving a headache for a while.

SELECT * FROM players WHERE user_id NOT IN (SELECT player_id FROM team_requests) 

Advertisement

Answer

You Can Try this. First you Can Select all Player IDs.

$player_ids = TeamRequest::select(‘player_id’)->get();

Then you can find Players

Player::whereNotIn(‘user_id’, $player_ids)->get();

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement