In this article, we will see the laravel whereIn and whereNotIn query examples. laravel query builder provides many different types of queries to filter data from databases. The whereIn method verifies that a given column's value is contained within the given array and the whereNotIn method verifies that the given column's value is not contained in the given array.
Also, you can check if the value exists or not using the whereIn function in laravel 6, laravel 7, and laravel 8. You may create whereIn and whereNotIn subquery in laravel 7/8.
So, let's see laravel 7/8 wherein the query and SQL in the query example.
Syntax:
Example:
SQL Query
SELECT * FROM students WHERE roll_no IN (1,2,3)
Laravel whereIn Query
public function index()
{
$students = Student::select("*")
->whereIn('roll_no', [1,2,3])
->get();
dd($students);
}
Laravel whereNotIn Query
public function index()
{
$roll_no = '1,2,3';
$array1 = explode(',', $roll_no);
$student = Student::select("*")
->whereNotIn('roll_no', $array1)
->get();
dd($student);
}
In this article, we will see how to create a zip file using zipArchive in laravel. Sometimes we have requirements to hav...
Sep-16-2020
In this article, we will see require ext-curl * is missing from your system in ubuntu. When we set up the laravel 9...
Feb-16-2023
In the ever-evolving landscape of web development, crafting a tailor-made user authentication system stands as a pivotal...
Aug-25-2023
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