In this article, we will see laravel 9 where condition example. Where condition is essential in each and every query in laravel. So, we will learn how to write multiple where conditions in laravel 9, and also we will see multiple columns in single where condition.
Where 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 where conditions in laravel 9 and multiple where clauses in laravel 9.
Syntax of the where() condition.
In this example, we will retrieve the user's records using the operator. This query retrieves votes column equal to 80 and age is greater than 25.
$users = DB::table('users')
->where('votes', '=', 80)
->where('age', '>', 25)
->get();
if you want to verify that a column is =
to a given value, you may pass the value as the second argument to the where
method.
$users = DB::table('users')->where('votes', 80)->get();
In this example, you may pass the multiple arrays of conditions in the single where condition.
$users = DB::table('users')->where([
['status', '=', '1'],
['plan', '!=', '1'],
['closed', '=', false],
])->get();
In this example, you can use any operator that is supported by your database system.
$users = DB::table('users')
->where('votes', '>=', 80)
->get();
$users = DB::table('users')
->where('votes', '<>', 80)
->get();
$users = DB::table('users')
->where('name', 'like', 'web%')
->get();
In this example, we will retrieve records using the model.
$users = User::where('is_active','=', true)->get();
You might also like:
In this article, we will see laravel 9 authentication using inertia js. Here, you can learn how to authenticat...
Dec-05-2022
Hello, laravel web developers! In this article, we'll see how to convert Word doc to PDF in laravel 11. In laravel 1...
Jul-01-2024
In this article, we will see an example of laravel 9 REST API with passport authentication. Also, perform CRUD...
Mar-13-2022
In this article, I will guide you through the process of installing the PHP XML extension in Ubuntu. The PHP XML extensi...
Jul-19-2023