Answers for "two condition in one laravel query"

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

two condition in one laravel query

$data = Sub_sub_category::select('sub_sub_cat_name','id')->where('sub_cat_id',$request->id)->where('status','1')->get();
Posted by: Guest on July-02-2021

Code answers related to "two condition in one laravel query"

Browse Popular Code Answers by Language