Support the ongoing development of Laravel.io →
Database Eloquent
Last updated 2 years ago.
0

I guess you can use the WHERE NOT IN query and pass in an array of ids of all related models.

Last updated 2 years ago.
0

Is there are way to generate such an array via eloquent? something like:

$id_array = Game::get()->id->toarray(); 
Last updated 2 years ago.
0

This should give you all the entries from game table, that are not equal to the specific user_id in the game table.

User::find($id)->games()->where('user_id', '!=', $id)->get();
Last updated 2 years ago.
0

DavidDomain said:

This should give you all the entries from game table, that are not equal to the specific user_id in the game table.

User::find($id)->games()->where('user_id', '!=', $id)->get();

This is actually not working as well. Since you select all games which for sure have user_id == $id, the result should allways be NULL.

Last updated 2 years ago.
0

There is no function from laravel to run this out of the box.

You have to join this manually:

$games = Game::leftJoin('game_user', function($join) use ($userId){
        $join->on('games.id', '=', 'game_users.game_id');
        $join->on('game_users.user_id', '=', \DB::raw("'".$userId."'"));
    })->whereNull('game_users.game_id')->get();
0

Sign in to participate in this thread!

Eventy

Your banner here too?

meneman meneman Joined 7 May 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.