1 public function index()
2 {
3 $search = "Har";
4
5 $users = User::select("*")->where('status', 1)
6 ->where(function($query) use ($search){
7 $query->where('first_name', 'LIKE', '%'.$search.'%')
8 ->orWhere('last_name', 'LIKE', '%'.$search.'%')
9 ->orWhere('email', 'LIKE', '%'.$search.'%');
10 })->get();
11
12 dd($users);
13 }
14
15# With Join
16 public function index()
17 {
18 $search = "Har";
19
20 $users = User::select("*")->where('status', 1)
21 ->where(function($query) use ($search){
22 $query->where('first_name', 'LIKE', '%'.$search.'%')
23 ->orWhere('last_name', 'LIKE', '%'.$search.'%')
24 ->orWhere('email', 'LIKE', '%'.$search.'%');
25 })
26 ->join('users_roles', 'users.id', '=', 'users_roles.user_id')
27 ->where('users_roles.role_id', '=', Role::USER_PARTICIPANT)->get();
28
29 dd($users);
30 }
1// ...
2$q->where(function ($query) {
3 $query->where('gender', 'Male')
4 ->where('age', '>=', 18);
5})->orWhere(function($query) {
6 $query->where('gender', 'Female')
7 ->where('age', '>=', 65);
8})
1//laravel
2// here, i have used two different where condition on a single column
3$today = Carbon::today();
4$data = Users::where('type',1)
5 ->where(function($query) use ($today) {
6 return $query->whereDate('updated_at','!=', $today)
7 ->orWhere('updated_at',null);
8 })
9 ->get();