Answers for "laravel where multiple conditions"

PHP
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);
    }

# With Join
  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);
    }
Posted by: Guest on November-24-2020
1

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);	
})
Posted by: Guest on August-04-2020
1

laravel where multiple conditions on single colmn

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

Code answers related to "laravel where multiple conditions"

Browse Popular Code Answers by Language