Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

Laravel - Add conditional where clause in query

$user_to_mail = User::where('store_id', $item->store_id)
                    ->when($store->notification_role_id > 0, function ($q) use ($store) {
                        return $q->where('role_id', $store->notification_role_id);
                    })
                    ->get();
 
PREVIOUS NEXT
Tagged: #Laravel #Add #conditional #clause #query
ADD COMMENT
Topic
Name
7+8 =