Laravel orWhere conditions with eloquent query example. Here, you will learn how to use laravel orWhere eloquent method with query builder and model. And as well as how to use laravel multiple orWhere conditions with queries.
This tutorial will take several examples of laravel orWhere conditions with query builder and eloquent model.
The following syntax represents the laravel orWhere clause:
orWhere(Coulumn_name, Value);
Now, you can see the following examples of laravel orWhere query with single and multiple conditions:
Example 1: Laravel orWhere with Query Builder
public function index()
{
$users = DB::table('users')
->where('id', 1)
->orWhere('email', '[email protected]')
->get();
dd($users);
}
Example 2: Laravel orWhere with Eloquent Model
public function index()
{
$users = User::where('id', 1)
->orWhere('email', '[email protected]')
->get();
dd($users);
}
When you dump the above given orWhere queries you will get the following SQL query:
SELECT * FROM users WHERE id = '1' OR email = '[email protected]'
Example 3: Laravel Multiple orWhere
public function index()
{
$users = User::where('name', 'like' , '%'.$qry.'%')
->orWhere(function($query) use($qry) {
$query->where('email','like','%'.$qry.'%')
->where('status','!=',$qry)
})->get();
dd($users);
}
Conclusion
Laravel orWhere condition query example tutorial, you have learned how to use laravel orWhere eloquent method with query builder and model for multiple columns and condtions.