Necesito ayuda para una consulta en laravel
Mi consulta personalizada: (Devolver resultado correcto)
Select * FROM events WHERE status = 0 AND (type="public" or type = "private")cómo escribir esta consulta en Laravel.
Event::where('status' , 0)->where("type" , "private")->orWhere('type' , "public")->get();Pero también está devolviendo todos los eventos públicos cuyo estado no es 0.
Estoy usando Laravel 5.4
Pase el cierre al where() :
Event::where('status' , 0) ->where(function($q) { $q->where('type', 'private') ->orWhere('type', 'public'); }) ->get();En su caso, puede simplemente reescribir la consulta...
select * FROM `events` WHERE `status` = 0 AND `type` IN ("public", "private");Y con Elocuente:
$events = Event::where('status', 0) ->whereIn('type', ['public', 'private']) ->get();Cuando desee tener un OR/AND agrupado, use un cierre:
$events = Event::where('status', 0) ->where(function($query) { $query->where('type', 'public') ->orWhere('type', 'private'); })->get();Utilizar este
$event = Event::where('status' , 0); $event = $event->where("type" , "private")->orWhere('type' , "public")->get();o esto
Event::where('status' , 0) ->where(function($result) { $result->where("type" , "private") ->orWhere('type' , "public"); }) ->get();