ItSolutionStuff.com

Laravel Eloquent orWhere() Condition Example

By Hardik Savani • April 16, 2024
Laravel

Today's topic is how to use or where condition in laravel eloquent. How works laravel orWhere() query. i will give you simple example of or where condition in laravel query builder. you can use laravel eloquent or where easily.

you can simple use orWhere eloquent method in laravel 6, laravel 7, laravel 8, laravel 9, laravel 10 and laravel 11.

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

Hardik Savani

Hardik Savani

I'm a full-stack developer, entrepreneur, and founder of ItSolutionStuff.com. Passionate about PHP, Laravel, JavaScript, and helping developers grow.

📺 Subscribe on YouTube

We Are Recommending You

Laravel Eloquent whereRelation() Condition Example

Read Now →

Laravel Eloquent whereHas() Condition Example

Read Now →

Laravel Eloquent Left Join Where Null Condition Example

Read Now →

Laravel Eloquent whereNotNull() Query Example

Read Now →

Laravel Multiple Where Condition Example

Read Now →

Laravel Eloquent WhereNotIn Query Example

Read Now →

Laravel Eloquent WhereIn Query Example

Read Now →

How to use whereHas with orWhereHas in Laravel?

Read Now →

Laravel Relationship Where Condition Example

Read Now →

Laravel Where Condition with Two Columns Example

Read Now →

Laravel Where Clause with date_format() Example

Read Now →

Laravel Eloquent Where Like Query Example Tutorial

Read Now →

Laravel Where Clause with MySQL Function Example

Read Now →

Laravel Query Builder Where Exists Example

Read Now →