Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

301
Views
Cómo usar múltiples condiciones OR, AND en consultas de Laravel

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

about 4 years ago · Santiago Trujillo
3 answers
Answer question

0

Pase el cierre al where() :

 Event::where('status' , 0) ->where(function($q) { $q->where('type', 'private') ->orWhere('type', 'public'); }) ->get();

https://laravel.com/docs/5.4/queries#parameter-grouping

about 4 years ago · Santiago Trujillo Report

0

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();
about 4 years ago · Santiago Trujillo Report

0

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();
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!