1$query->where([
2 ['column_1', '=', 'value_1'],
3 ['column_2', '<>', 'value_2'],
4 [COLUMN, OPERATOR, VALUE],
5 ...
6])
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})
1if ($request->search) {
2
3 $users = User::where('type', '=', 'Customer')
4 ->where(function ($query) use ($request) {
5 $query->where('name', "like", "%" . $request->search . "%");
6 $query->orWhere('mobile', "like", "%" . $request->search . "%");
7 })->get();
8 }
9