laravel where with multiple conditions code example

Example 1: laravel where multiple conditions

$query->where([
    ['column_1', '=', 'value_1'],
    ['column_2', '<>', 'value_2'],
    [COLUMN, OPERATOR, VALUE],
    ...
])

Example 2: multiple logical condition in laravel query

// ...
$q->where(function ($query) {
    $query->where('gender', 'Male')
        ->where('age', '>=', 18);
})->orWhere(function($query) {
    $query->where('gender', 'Female')
        ->where('age', '>=', 65);	
})

Example 3: laravel where multiple conditions on single colmn

// here, i have used two different where condition on a single column
$data = Users::where('type',1)
        ->where(function($query) {
            return $query->whereDate('updated_at','!=', Carbon::today())
            ->orWhere('updated_at',null);
         })
         ->get();

Example 4: laravel select record with several conditions

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

Example 5: laravel select record with several conditions

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

Tags:

Php Example