DEV Community

Techsolutionstuff
Techsolutionstuff

Posted on • Originally published at techsolutionstuff.com

Laravel where and orWhere Condition Example

In this artical we will see how to use where and orwhere condition in 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 8

where(Coulumn Name, Operator, Value);

Example of where() condition in laravel 8

$users = DB::table('users')
                ->where('id', '=', 5)
                ->where('department', '=', 'Designer')
                ->where('age', '>', 25)
                ->get();
Enter fullscreen mode Exit fullscreen mode

Now, we will see orWhere() condition in laravel 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='5' OR salary='10000';
Enter fullscreen mode Exit fullscreen mode

Example of orWhere() condition in laravel 8

$users = DB::table('users')
                    ->where('salary', '>', 10000)
                    ->orWhere('name', 'Mark')
                    ->get();
Enter fullscreen mode Exit fullscreen mode

You might also like :

Top comments (0)