Laravel where and orWhere Condition Example

WebSolutionStuff | Jan-11-2021 | Categories : Laravel

Hello Guys,

Today in this post I will give you Laravel where and orWhere Condition Example. I will give you very simple example of laravel where() and orWhere() condition and also I will give you example of where() and orWhere in single query in laravel 6/7/8.

You can use the where and orwhere method in laravel 6, laravel 7 and laravel 8.

For where() and orWhere() method the first argument is the name of the column. The second argument is an operator, which can be any of the database's supported operators. The third argument is the value to compare against the column's value.

 

Syntax of where() query in laravel 6/7/8

where(Coulumn Name, Operator, Value);

 

Example of where() condition in laravel 6/7/8

$users = DB::table('users')
                ->where('id', '=', 10)
                ->where('department', '=', 'web development')
                ->where('age', '>', 35)
                ->get();

 

Now I will show you example of orWhere() query in laravel 6/7/8 and how to write orWhere() condition in laravel. So first we will see SQL query for better understanding.

SQL OR Example

SELECT * FROM users WHERE id='10' OR salary='20000';

 

Example of orWhere() condition in laravel 6/7/8

$users = DB::table('users')
                    ->where('salary', '>', 20000)
                    ->orWhere('name', 'Maria')
                    ->get();

 

Featured Post



Follow us
facebooklogo github instagram twitter