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);
Eloquent orWhere() Condition Example
Now, you can see the following examples of laravel orWhere query with single and multiple conditions:
- Example 1: Laravel orWhere with Query Builder
- Example 2: Laravel orWhere with Eloquent Model
- Example 3: laravel orwhere multiple conditions
Example 1: Laravel orWhere with Query Builder
public function index() { $users = DB::table('users') ->where('id', 1) ->orWhere('email', 'example@gmail.com') ->get(); dd($users); }
Example 2: Laravel orWhere with Eloquent Model
public function index() { $users = User::where('id', 1) ->orWhere('email', 'example@gmail.com') ->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 = 'example@gmail.com'
Example 3: laravel orwhere multiple conditions
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
That’s all, you have learned how to use laravel orWhere eloquent method with query builder and model for multiple columns and condtions.