In this article, we will see Laravel 9 whereIn / whereNotIn / orWhereIn / orWhereNotIn Query Example. The whereIn() method is used to check the value in a given range of the value. So, we will learn laravel 9 whereIn query, laravel 9 whereNotIn query, laravel 9 orWhereIn query, laravel 9 orWhereNotIn query example.
The whereIn
method verifies that a given column's value is contained within the given array. The whereNotIn
method verifies that the given column's value is not contained in the given array.
Syntax of SQL:
SELECT column_name(s)
FROM table_name
WHERE column_name IN (value1, value2, ...);
In this example, we will retrieve all records of employees with IN conditions.
SELECT * FROM employee WHERE emp_id IN (1,2,3)
Syntax of Laravel:
whereIn(Coulumn Name, Array of Value)
In this example, we will retrieve data using the whereIn() method.
$employee = DB::table('employee')
->whereIn('id', [1, 2, 3])
->get();
In this example, we will retrieve data using the whereNotIn() method.
$employee = DB::table('employee')
->whereNotIn('id', [1, 2, 3])
->get();
In this example, we will retrieve data using the orWhereIn() method.
$employee = DB::table('employee')
->where('role','=','software engineer')
->orWhereIn('emp_id', [1, 2, 3])
->get();
In this example, we will retrieve data using the orWhereNotIn() method.
$employee = DB::table('employee')
->where('role','=','software engineer')
->orWhereNotIn('emp_id', [1, 2, 3])
->get();
You might also like:
In tutorial we will see how to validate laravel 8 image upload validation. In laravel 7/8 you can validate image using t...
Dec-15-2021
In this article, I will guide you through the process of installing the php-zip extension on Ubuntu. The php-zip extensi...
Jul-14-2023
In this article, we will see how to set auto database backup using the cron scheduler in laravel. here we will set ...
Feb-18-2021
In this tutorial we will see laravel 8 user roles and permissions without package.Roles and permissions are an impo...
Sep-13-2021