In this article, we will see the laravel 9 orWhere condition example. Where condition is joined together using the and
operator. The orWhere condition is joined together using the or
operator. The orWhere method is the same as the where() method. So, we will learn how to write multiple where conditions with orWhere in laravel 9, and also we will see SQL query of or condition.
The orWhere condition has three arguments, the first argument is the name of the column. The second argument is an operator. The third argument is the value to compare against the column's value.
So, let's see orWhere conditions in laravel 9.
Syntax of the orWhere() condition.
In this example, we will get the records using SQL query with OR condition.
SELECT * FROM users WHERE salary > 20000 OR role='software engineer';
In this example, we will retrieve records of the user's who has votes greater than 80 or whose name is dell.
$users = DB::table('users')
->where('votes', '>', 80)
->orWhere('name', 'dell')
->get();
In this example, we will see the orWhere() condition with a subquery.
$users = DB::table('users')
->where('votes', '>', 80)
->orWhere(function($query) {
$query->where('name', 'dell')
->where('votes', '>', 50);
})
->get();
The example above will produce the following SQL.
select * from users where votes > 80 or (name = 'dell' and votes > 50)
In this example, we will retrieve data using the where() and orWhere() with the model.
$users = User::where('is_active','=', true)->orWhere('plan','!=','basic')->get();
You might also like:
In this post we will see how to get selected checkbox value in array using jquery. Here i will give you some example to&...
May-24-2021
In this article, we will see how to remove/hide columns while export data in datatables in laravel 8. When we are u...
Oct-13-2020
Hello Dev, In this example we will see how to push array element in node.js example. I will share some example about&...
Oct-11-2021
In this article, we will see an example of laravel 8 export buttons in datatables. If you want to export data...
Oct-14-2020