laravel where multiple conditions
$query->where([
['column_1', '=', 'value_1'],
['column_2', '<>', 'value_2'],
[COLUMN, OPERATOR, VALUE],
...
])
laravel where multiple conditions
$query->where([
['column_1', '=', 'value_1'],
['column_2', '<>', 'value_2'],
[COLUMN, OPERATOR, VALUE],
...
])
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);
}
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);
})
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();
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us