Nick Nick - 3 years ago 205
SQL Question

convert raw query to laravel on nested where

How do I convert this to laravel 5.1 eloquent. $rest_id and $shop_id are variables.

`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%'

Answer Source

Try this code:

->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('', 'like', '%ODRID201709181700343052%')
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download