Answers for "how condition for multiple row by orwhere laravel"

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
0

how condition for multiple row by orwhere laravel

if ($request->search) {
             
     $users = User::where('type', '=',  'Customer')
        ->where(function ($query) use ($request) {
            $query->where('name', "like", "%" . $request->search . "%");
            $query->orWhere('mobile', "like", "%" . $request->search . "%");
        })->get();   
  }
Posted by: Guest on June-29-2021

Browse Popular Code Answers by Language