Laravel Multiple Where Condition Tutorial


Share:
Published By: Admin, Published On: Jun 28, 2021, Category: Laravel

Hello Friends,

Now let's see example of how to use laravel multiple where condition in laravel. This is a short guide on laravel if multiple where condition. We will use how to use multiple where condition in laravel. Here you will learn how to use multiple where condition in laravel. We will use how to use if multiple where condition in laravel. Let's get started with how to multiple where condition use in laravel.

Here i will give you many example how you can check multiple where condition in laravel.

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:

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

OR

->where([
    ['COLUMN_NAME', 'OPERATOR', 'VALUE'],
    ['COLUMN_NAME', 'OPERATOR', 'VALUE']
]);
Example :

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

SQL Query :

SELECT * FROM `companies` 
WHERE name = 'laravel' AND email = 0

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

Example : 1
/**
 * Write code on Method
 *
 * @return response()
*/
public function index()
{
	$companies = Company::select('*')
                ->where('name', '=', 'laravel')
                ->where('email', '=', 0)
                ->get()
                ->toArray();
    dd($companies);
}	
Example : 2
/**
 * Write code on Method
 *
 * @return response()
*/
public function index()
{
	$companies = Company::select('*')
                ->where([
                    ['name', '=', 'test'],
                    ['email', '=', 0]
                ])
                ->get()
                ->toArray();
    dd($companies);
}

It will help you....

Share: