在嵌套的位置将原始查询转换为laravel

时间:2017-10-02 06:58:08

标签: sql laravel eloquent

如何将此转换为laravel 5.1 eloquent。 $ rest_id和$ shop_id是变量。

WHERE
    `orderbookings`.`status` = 1 AND 
    ((`shop_customer_details`.`restaurant_id` = $rest_id AND `shop_customer_details`.`shop_id` = $shop_id) OR 
     `orderbookings`.`shop_customer_detail_id` = 0) AND 
    `orderbookings`.`id` LIKE '%ODRID201709181700343052%'

1 个答案:

答案 0 :(得分:2)

试试这段代码:

->where('orderbookings.status', 1)
->where(function($q) use ($rest_id, $shop_id) {
        $q->where(function($query) use ($rest_id, $shop_id) {
                $query->where('shop_customer_details.restaurant_id', $user_id)
                      ->where('shop_customer_details.shop_id', $shop_id);
            })
          ->orWhere('orderbookings.shop_customer_detail_id', 0)
        })
->where('orderbookings.id', 'like', '%ODRID201709181700343052%')