Multiple Where Condition in Laravel Example

Multiple Where Condition in Laravel Example

In this example i exaplain Multiple Where Condition in Laravel Example. Today, I’m teaching you how to write several times when a paragraph on a laravel question builder. i will give you an example of multiple where condition in laravel. you can easily extract many when the question situation with laravel 6, laravel 7 and laravel 8.

Most likely, we need to write more when the situation with laravel. as we know we can use where the clause applies() in laravel. but if you want repetitive writing multiple where condition in laravel then I will give you two examples of how to write more often where the caravan is laravel.

Read Also :  Laravel 8 QR Code Generate Example

Laravel multiple where model conditions. In this tutorial, you will learn how to use the interactive questionnaire in web laravel apps.

In some cases, you may want to use download data for multiple locations where the situation is in laravel apps, This tutorial will show you many different examples of many applications where situations have questionable questions.

You can also use it when the clause and laravel search query have multiple scenarios, update the query with multiple scenarios, delete query with multiple scenarios, and multiple-case relationships in laravel.

Read Also :  Razorpay Payment Gateway Integration in Laravel

Let’s take some examples:

Syntax of writing multiple Where Condition in Laravel

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

OR

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

Example 1: Laravel multiple where condition

Laravel multiple where conditions:

public function index()
{
 $users = User::select('*')
   ->where('active', '=', 1)
   ->where('is_ban', '=', )
   ->get();
 dd($users);
}

Example 2: Multiple Where Condition

Laravel multiple condition in where clause:

public function index()
{
 $users = User::select('*')
   ->where([
     ['active', '=', 1],
     ['is_ban', '=', ]
   ])
  ->get();
  dd($users);
}

Example 3: Laravel multiple where with Relationship

Go to your model and create scopes, like follow

public function scopeActive($query) {
     return $query->where('active', '=', 1);
 }
 public function scopeThat($query) {
     return $query->where('that', '=', 1);
 }

Then call scops:

public function index()
{
    //Then call the scopes as given below
    $users = User::active()->that()->get();
}