php - Laravel - How to do nested where with And and OR in same query -


i have following query

$updates = folderlocker::where('created_at', 'like', $date . '%')                 ->orwhere('date_forwarded', 'like', $date . '%')                 ->orwhere('date_locked', 'like', $date . '%')                 ->orwhere('date_completed', 'like', $date . '%')                 ->wherein('videographer_id', $videographerarray)                 ->orderby('client_id', 'desc')                  ->tosql(); 

it generates

select * `folder_lockers` `created_at` ? or `date_forwarded` ? or `date_locked` ? or `date_completed` ? , `videographer_id` in (?, ?, ?, ?, ?, ?, ?) order `client_id` desc 

how can make wherein clause main 1 , or clauses in and?

you can group wheres in closure, this:

$updates = folderlocker::wherein('videographer_id', $videographerarray)                ->where(function ($query) use ($date) {                    $query->where('created_at', 'like', $date . '%')                        ->orwhere('date_forwarded', 'like', $date . '%')                        ->orwhere('date_locked', 'like', $date . '%')                        ->orwhere('date_completed', 'like', $date . '%');                })                                ->orderby('client_id', 'desc'); 

Comments

Popular posts from this blog

angular - Is it possible to get native element for formControl? -

unity3d - Rotate an object to face an opposite direction -

javascript - Why jQuery Select box change event is now working? -