search
LoginSignup
0

More than 3 years have passed since last update.

posted at

updated at

Organization

Laravelでサブクエリをメソッド使いたい。joinSub()

laravelでサブクエリをつかいたい。

DB::rawを使って生sqlでサブクエリを読み込ませる方法が過去あったが、5.6からjoinSubというメソッドができたらしい


$hoges = DB::table('hoge')
             ->where('fuga')
             ->select('piyo');

function hogeGet () : object
{
    return DB::table('hogehoge')
            ->joinSub($hoges,'hoges', function ($join) {
                $join->on('hogehoge.id', '=', 'hoges.hogehoge_id');
            })
            ->get();
}

Laravel News
Laravel 5.6.17 Released
https://laravel-news.com/laravel-5-6-17

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
What you can do with signing up
0