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

166
Views
laravel query builder to add and or condition

Receiving the request in array format

[
    [ 
        [ 
        'condition1', 
        'value1',
        ],
        [ 
        'condition2', 
        'value2',
        ],
    ], 
    [ 
    'condition3', 
    'value4',
    ]
]

Im trying to build query builder with values1 and values 2 in 'or' condition and value3 in 'and' condition

$result = DB::table('table ')

foreach($values as $value){ //
  $result->where(function ($qry) use ($value) { // array 0,1 with and condition
    foreach($value as $val){ // values1 , values2
       $qry->where();
    }

  });

}

How to add 'or' condition between the values1 and values2 and then 'and' condition with value3.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Don't need any loop, you need sub query, like this :

$result = DB::table('table')
   ->where(function($query) use($value1) {
      $query->where('condition1', $value1)
            ->orWhere('condition2', $value1);
   })
   ->where('condition3', $value2)
   ->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!