Laravel Fluent Query Builder Join with subquery

前端 未结 7 684
天涯浪人
天涯浪人 2020-11-27 13:03

Okay after hours of research and still using DB::select I have to ask this question. Because I am about to trough my computer away ;).

I want to get the last input o

7条回答
  •  暖寄归人
    2020-11-27 13:14

    I can't comment because my reputation is not high enough. @Franklin Rivero if you are using Laravel 5.2 you can set the bindings on the main query instead of the join using the setBindings method.

    So the main query in @ph4r05's answer would look something like this:

    $q = DnsResult::query()
        ->from($dnsTable . ' AS s')
        ->join(
            DB::raw('(' . $qqSql. ') AS ss'),
            function(JoinClause $join) {
                $join->on('s.watch_id', '=', 'ss.watch_id')
                     ->on('s.last_scan_at', '=', 'ss.last_scan');
            })
        ->setBindings($subq->getBindings());
    

提交回复
热议问题