1

I want to make a query like this

SELECT * FROM batches WHERE id = 20 AND status = 3 OR status = 8

I tried following query but it returning me all records with status = 8

Batch::where('id', 20)->where('status','3')->orwhere('status','8');

What mistake did I make?

Thanks in advance!

2 Answers 2

2

you can use whereIn

Batch::where('id', 20)->whereIn('status', [3,8]);
Sign up to request clarification or add additional context in comments.

Comments

1

You can use Advanced Wheres

 Batch::where('id', 20)->where(function($query) use ($staus){
       foreach($status as $stat){
           $query->orWhere('status','=',$stat);
       }
 })->get();

1 Comment

PHP methods and functions are case insensitive.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.