Thursday, September 4, 2025
HomeLanguagesLaravel Eloquent orWhere() Condition Example

Laravel Eloquent orWhere() Condition Example

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', '[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 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.

Recommended Laravel Posts

RELATED ARTICLES

Most Popular

Dominic
32264 POSTS0 COMMENTS
Milvus
81 POSTS0 COMMENTS
Nango Kala
6632 POSTS0 COMMENTS
Nicole Veronica
11800 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11860 POSTS0 COMMENTS
Shaida Kate Naidoo
6749 POSTS0 COMMENTS
Ted Musemwa
7025 POSTS0 COMMENTS
Thapelo Manthata
6698 POSTS0 COMMENTS
Umr Jansen
6718 POSTS0 COMMENTS