Laravel 9 Multiple Where Condition Query Example

Websolutionstuff | Sep-30-2022 | Categories : Laravel

In this article, we will see the laravel 9 and laravel 10 multiple where condition query example. We will learn how to write multiple where clauses in the laravel 9 query builder. Also, we will use the where() function in laravel 9/10. Sometimes we need multiple conditions in the query.

So, we will give you how to create multiple where clause queries using laravel 9 eloquent. Also, you can use this multiple where condition in laravel 8, laravel 9, and laravel 10.

The most basic call to the where method requires three arguments. The first argument is the name of the column. The second argument is an operator, which can be any of the database's supported operators.

So, let's multiple where conditions in laravel 9 and laravel 9 where conditions.

Syntax of multiple where condition.

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

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

Also, you can write on single where condition.

->where([

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

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

    ]);

 

 

Example: SQL Query

SQL query with multiple where conditions.

SELECT * FROM `users` 

WHERE votes = 100 AND votes > 35;

 

Example: laravel multiple where clause

For example, the following query retrieves users where the value of the votes column is equal to 100 and the value of the age column is greater than 35.

Example 1:

$users = DB::table('users')
                ->where('votes', '=', 100)
                ->where('age', '>', 35)
                ->get();

 

Example 2:

$users = DB::table('users')
			->where([
                    ['votes', '=', 100],
                    ['votes', '>', 35]
                ])
                ->get();

 

 

Conditions using Array:

$users = User::where([
       'column1' => value1,
       'column2' => value2,
       'column3' => value3
])->get();

 

This query like produced below:

SELECT * FROM TABLE WHERE column1 = value1 and column2 = value2 and column3 = value3

 


You might also like :

Recommended Post
Featured Post
How To Integrate Stripe Payment Gateway In Laravel 9
How To Integrate Stripe Paymen...

In this article, we will see how to integrate the stripe payment gateway in laravel 9. stripe payment gateway is in...

Read More

Apr-10-2022

How To Count Days Excluding Weekends And Holidays In Laravel 9
How To Count Days Excluding We...

In this article, we will see how to count days excluding weekends and holidays in laravel 9. Here, we will learn to...

Read More

Jan-24-2023

Laravel 9 User Roles and Permissions Without Package
Laravel 9 User Roles and Permi...

In this article, we will see laravel 9 user roles and permissions without package. Roles and permissions are an imp...

Read More

Apr-14-2022

Laravel 9 to_route() and str() Helper Function
Laravel 9 to_route() and str()...

In this article, we will see laravel 9 to_route() and str() helper function. The to_route function g...

Read More

Oct-03-2022