Laravel whereIn and whereNotIn Query Example

Websolutionstuff | Jan-16-2021 | Categories : Laravel PHP

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.


whereIn(Coulumn_name, Array)



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])


Laravel whereNotIn Query

public function index()
    $roll_no = '1,2,3';
    $array1 = explode(',', $roll_no);
    $student = Student::select("*")
                    ->whereNotIn('roll_no', $array1)


Recommended Post
Featured Post
Laravel Authentication Using Breeze
Laravel Authentication Using B...

In this article, we will share you new information about laravel authentication using a breeze. Laravel Breeze...

Read More


How To Get Selected Checkbox List Value In Jquery
How To Get Selected Checkbox L...

In this tutorial, I will explain you to how to get the selected checkbox value from a checkbox list in jquery, If y...

Read More


How to Install PHP DOM Extension in Ubuntu 23.04
How to Install PHP DOM Extensi...

In this tutorial, I will guide you through the process of installing the PHP DOM Extension in Ubuntu 23.04. The PHP DOM...

Read More


How To Image Upload With Preview In Angular 15
How To Image Upload With Previ...

In today's world of web development, being able to upload images with a preview feature is a common requirement for...

Read More