How to use multiple where condition in Laravel?

You can add where clause to a model like ->where(/*condition*/)

User::where('status' ,'=' ,1)->where('payment', '=' ,1)->get();

Sometimes We need to add orWhere condition to our queries, between two cases. This might interfere with other conditions so we need to pass them in a function.

->where( function($query) {
	$query->where('parent_id', '=', 1)
              ->orWhere('parent_id','=' ,2);
} )

To get external variables pass them with use

->where( function($query) use ($case1, $case2) {
	$query->where('parent_id', '=', $case1)
              ->orWhere('parent_id', '=' ,case2);
} )

One thought on “How to use multiple where condition in Laravel?

Leave a Reply

Your email address will not be published. Required fields are marked *