ItSolutionStuff.com

Laravel Multiple Where Condition Example

By Hardik Savani • April 16, 2024
Laravel

Today, i teach you how to write multiple where clause in laravel query builder. i will give you example of laravel eloquent multiple where conditions. you can easily execute multiple where condition in query with laravel 6, laravel 7, laravel 8, laravel 9, laravel 10 and laravel 11.

Almost, we need to write multiple where condition with laravel. as we know we can use where clause using where() in laravel. but if you want to write multiple where clause in laravel then i will give you two example of how to write multiple where clause in laravel.

You can see both syntax of writing multiple where condition:

->where('COLUMN_NAME', 'OPERATOR', 'VALUE')

->where('COLUMN_NAME', 'OPERATOR', 'VALUE')

OR

->where([

['COLUMN_NAME', 'OPERATOR', 'VALUE'],

['COLUMN_NAME', 'OPERATOR', 'VALUE']

]);

Now i will give you example of how to write multiple where condition with laravel.

If you have sql query like as bellow with multiple where condition:

SQL Query:

SELECT * FROM `users`

WHERE active = 1 AND is_ban = 0

Then you can write your sql qurey like as bellow both way:

Example 1:

public function index()

{

$users = User::select('*')

->where('active', '=', 1)

->where('is_ban', '=', 0)

->get();

dd($users);

}

Example 2:

public function index()

{

$users = User::select('*')

->where([

['active', '=', 1],

['is_ban', '=', 0]

])

->get();

dd($users);

}

I hope it can help you...

Hardik Savani

Hardik Savani

I'm a full-stack developer, entrepreneur, and founder of ItSolutionStuff.com. Passionate about PHP, Laravel, JavaScript, and helping developers grow.

📺 Subscribe on YouTube

We Are Recommending You

Laravel Where Clause with Function Query Example

Read Now →

Laravel Sum Query with Where Condition Example

Read Now →

Laravel Eloquent whereRelation() Condition Example

Read Now →

Laravel Eloquent whereHas() Condition Example

Read Now →

Laravel Eloquent whereNotNull() Query Example

Read Now →

Laravel Eloquent WhereNotIn Query Example

Read Now →

Laravel Eloquent WhereIn Query Example

Read Now →

How to Create and Use Query Scope in Laravel Eloquent

Read Now →

How to Use If Condition in Laravel Select Query?

Read Now →

How to use Union Query with Laravel Eloquent?

Read Now →

Laravel Many to Many Eloquent Relationship Tutorial

Read Now →

How to Search Comma Separated Values In Laravel?

Read Now →

Laravel Group By with Month and Year Example

Read Now →

Laravel Eloquent Where Like Query Example Tutorial

Read Now →