阅读(2969) (2)

Laravel 8 Left Join / Right Join 语句

2021-07-07 09:14:22 更新

如果你想使用 「左连接」或者 「右连接」代替「内连接」 ,可以使用 leftJoin 或者 rightJoin 方法。这两个方法与 join 方法用法相同:

$users = DB::table('users')
            ->leftJoin('posts', 'users.id', '=', 'posts.user_id')
            ->get();

$users = DB::table('users')
            ->rightJoin('posts', 'users.id', '=', 'posts.user_id')
            ->get();