lundi 3 juillet 2017

Is there an Eloquent way of doing a leftjoin in Laravel 5.4

Is there a eloquent way to do a left join in Laravel?

We'd like to get all games and fill in the progress for each one if it exists in user_games.

Right now we've written the following solution, however this isn't eloquent at all, which we like it to be.

public function usergames($user_id) { return DB::table('games')->leftJoin('user_games', function ($join) use ($user_id) { $join->on('user_games.game_id', '=', 'games.id')->where('user_games.user_id', '=', $user_id); })->get(); }

DB model: enter image description here

Thanks in advance!



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire