Here, i will show you laravel or where condition in model. This tutorial will give you simple example of laravel orwhere condition. This tutorial will give you simple example of or where laravel example. i explained simply about or where in laravel eloquent Let's see bellow example or where condition in laravel.
If you need to use sql or where query in laravel then you can use it. Laravel provide orWhere() to use sql or query query. in or where() we just need to pass two argument one is column name and will be value.
You can see bellow syntax on orWhere query in laravel:
orWhere(Coulumn_name, Value);
Now i will give you three example of how to use orWhere query in laravel application. So let's see those example how it works.
Example 1:
SQL Query:
SELECT *
FROM users
WHERE id = '23' OR email = 'itsolutionstuff@gmail.com'
Laravel Query:
public function index()
{
$users = DB::table('users')
->where('id', 23)
->orWhere('email', 'itsolutionstuff@gmail.com')
->get();
dd($users);
}
Example 2:
Here is another example of how it works with model. you can work as like bellow:
public function index()
{
$users = User::select("*")
->where('id', 23)
->orWhere('email', 'itsolutionstuff@gmail.com')
->get();
dd($users);
}
I hope it can help you...
Do you like below Tutorials ?
- PHP Laravel 5.5 - import export data into excel and csv using maatwebsite
- Laravel 7.x and 6.x create custom facade example from scratch
- Node JS - Get Real time online users counter using socket io example
- PHP Laravel 7.x and 6.x - Bootstrap Admin Theme Integration example from scratch
- MySQL Query - How to select records of today to next Sunday ?
- Laravel 7.x and 6.x - username custom validation example
- Laravel 5.5 - Import Extract zip file using chumper/zipper package
- PHP Laravel Set Custom Validation Error Messages Example