Laravel where and orWhere Condition Example

Websolutionstuff | Jan-11-2021 | Categories : Laravel PHP

In this article, we will see laravel where and orWhere condition example. we will give you a very simple example of the laravel where() and orWhere() condition and also we will give you an example of where() and orWhere in a single query in laravel 6/7/8. You can use the where and orwhere method in laravel 6, laravel 7, and laravel 8.

For the where() and orWhere() methods 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.

So, let's see laravel 7/8 where query and laravel 7/8 orwhere query.

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

where(Column 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 an 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();

 

Recommended Post
Featured Post
How To Get Current Route In React JS
How To Get Current Route In Re...

As a web developer using React JS, I've come to appreciate the power and efficiency of this JavaScript library. Its...

Read More

Aug-11-2023

How To Get Multiple Checkbox Value In Javascript
How To Get Multiple Checkbox V...

Checkboxes let us make multiple choices. But how do you actually use them in JavaScript? It might seem tricky, especiall...

Read More

Jan-10-2023

Laravel Authentication Using Breeze
Laravel Authentication Using B...

In this article, we will share you new information about laravel authentication using a breeze. Laravel Breeze...

Read More

Feb-05-2021

Laravel 9 Image Upload Example
Laravel 9 Image Upload Example

In this tutorial, I will explain the laravel 9 image upload example. image or file upload is the most common task in web...

Read More

Feb-28-2022