duanji9264 2016-07-15 09:51
浏览 77
已采纳

laravel 5.2嵌套Where子句

How to perform a where clause using laravel eloquent with the following query:

select * from stats where payed = 1 AND WHERE (user_id = 1 OR owner_id = 1)

I don't know how to modify this code for this:

    $payouts = Stat::where('payed', '1')
            ->???(function ($query) {
                $query->where('owner_id', Auth::user()->id)
                      ->where('user_id', Auth::user()->id);
            })->get();
  • 写回答

3条回答 默认 最新

  • dqf35839 2016-07-15 09:56
    关注

    Change like this

    $payouts = Stat::where('payed', '1');
            $payouts->where(function ($payouts) {
                $payouts->where('owner_id', Auth::user()->id)
                      ->orWhere('user_id', Auth::user()->id);
            })->get();
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?