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

Recommended Laravel Posts

AuthorDevendra Dode

Greetings, I'm Devendra Dode, a full-stack developer, entrepreneur, and the proud owner of Tutsmake.com. My passion lies in crafting informative tutorials and offering valuable tips to assist fellow developers on their coding journey. Within my content, I cover a spectrum of technologies, including PHP, Python, JavaScript, jQuery, Laravel, Livewire, CodeIgniter, Node.js, Express.js, Vue.js, Angular.js, React.js, MySQL, MongoDB, REST APIs, Windows, XAMPP, Linux, Ubuntu, Amazon AWS, Composer, SEO, WordPress, SSL, and Bootstrap. Whether you're starting out or looking for advanced examples, I provide step-by-step guides and practical demonstrations to make your learning experience seamless. Let's explore the diverse realms of coding together.

Leave a Reply

Your email address will not be published. Required fields are marked *