In this tutorial you will learn about the Laravel orWhere Condition with Eloquent Query Example and its application with practical example.
In this Laravel orWhere conditions with eloquent query example tutorial, I’ll show you how to use laravel orWhere method in laravel query builder and model. In this article you will also learn to use laravel orWhere with multiple conditions. In this tutorial I’ll share different use case of laravel orWhere eloquent method. In this Laravel orWhere conditions with eloquent query tutorial you will learn about the syntax and use of Laravel orWhere method.
Laravel orWhere clause syntax
Here is the general syntax of the laravel orWhere method:
1 |
orWhere(Coulumn_name, Value); |
Laravel orWhere Query
In this example query we will learn to use orWhere clause with single and multiple where condition.
Laravel orWhere with Query Builder
In this example you will learn to use orWhere clause with laravel query builder. You can use laravel orWhere with query builder as following:
Example:-
1 2 3 4 5 6 7 8 9 |
public function index() { $users = DB::table('users') ->where('id', 1) ->orWhere('email', 'example@gmail.com') ->get(); dd($users); } |
Laravel orWhere with Eloquent Model
In this example you will learn to use orWhere clause with laravel eloquent model. You can use laravel orWhere with eloquent model as following:
1 2 3 4 5 6 7 8 |
public function index() { $users = User::where('id', 1) ->orWhere('email', 'example@gmail.com') ->get(); dd($users); } |
The above given whereNull query you will get the following SQL query:
1 |
SELECT * FROM users WHERE id = '1' OR email = 'example@gmail.com' |
Laravel Multiple orWhere
In this example you will learn to use multiple orWhere clause. You can use multiple orWhere with eloquent model as following:
1 2 3 4 5 6 7 8 9 |
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); } |