multiple where laravel 8 code example
Example 1: multiple orwhere condition in laravel
public function index()
{
$search = "Har";
$users = User::select("*")->where('status', 1)
->where(function($query) use ($search){
$query->where('first_name', 'LIKE', '%'.$search.'%')
->orWhere('last_name', 'LIKE', '%'.$search.'%')
->orWhere('email', 'LIKE', '%'.$search.'%');
})->get();
dd($users);
}
public function index()
{
$search = "Har";
$users = User::select("*")->where('status', 1)
->where(function($query) use ($search){
$query->where('first_name', 'LIKE', '%'.$search.'%')
->orWhere('last_name', 'LIKE', '%'.$search.'%')
->orWhere('email', 'LIKE', '%'.$search.'%');
})
->join('users_roles', 'users.id', '=', 'users_roles.user_id')
->where('users_roles.role_id', '=', Role::USER_PARTICIPANT)->get();
dd($users);
}
Example 2: laravel select record with several conditions
public function index(){ $users = User::select('*') ->where('active', '=', 1) ->where('is_ban', '=', 0) ->get(); dd($users);}
Example 3: laravel select record with several conditions
public function index(){ $users = User::select('*') ->where([ ['active', '=', 1], ['is_ban', '=', 0] ]) ->get(); dd($users);}