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

309
Views
How to use multiple OR,AND condition in Laravel queries

I need help for query in laravel

My Custom Query: (Return Correct Result)

Select * FROM events WHERE status = 0 AND (type="public" or type = "private")

how to write this query in Laravel.

Event::where('status' , 0)->where("type" , "private")->orWhere('type' , "public")->get();

But it's returning all public events that status is not 0 as well.

I am using Laravel 5.4

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

Pass closure into the 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

over 4 years ago · Santiago Trujillo Report

0

In your case you can just rewrite the query...

select * FROM `events` WHERE `status` = 0 AND `type` IN ("public", "private");

And with Eloquent:

$events = Event::where('status', 0)
    ->whereIn('type', ['public', 'private'])
    ->get();

When you want to have a grouped OR/AND, use a closure:

$events = Event::where('status', 0)
    ->where(function($query) {
        $query->where('type', 'public')
            ->orWhere('type', 'private');
    })->get();
over 4 years ago · Santiago Trujillo Report

0

Use this

$event = Event::where('status' , 0);

$event = $event->where("type" , "private")->orWhere('type' , "public")->get();

or this

Event::where('status' , 0)
     ->where(function($result) {
         $result->where("type" , "private")
           ->orWhere('type' , "public");
     })
     ->get();
over 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!