Hello Artisan
In this tutorial i will discuss about multiple orWhere conditon in laravel 7.x. I’m going to show you about laravel 7.x eloquent multiple orwhere condition. If you don't know how to use multiple orWhere in Laravel eloquent query, then this multiple orWhere query example is for you.
If you need to use sql multiple or where query in laravel then you can use this methodology which i am going to show. Laravel provide orWhere() to use sql or query query multiple time. in or where() we just need to pass two argument one is column name and will be value.
You must follow bellow syntax on orWhere query in laravel:
Laravel orWhere Query Example
public function index()
{
$search = \App\Model::all();
$users = User::select("*")
->where('first_name', 'LIKE', '%'.$search.'%')
->orWhere('last_name', 'LIKE', '%'.$search.'%')
->orWhere('email', 'LIKE', '%'.$search.'%')
->get();
dd($users);
}
Read also : Laravel Eloquent with whereNull() Query Example
Multiple orWhere with where condition Example
public function index()
{
$search = \App\Model::all();
$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);
}
Hope it can help you.
#laravel #laravel-eloquent