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 8 Google Bar Chart Example
Laravel 8 Google Bar Chart Exa...

Today, we will see laravel 8 google bar chart example, Google charts is use to visualize data on you...

Read More


Laravel Unique Validation on Update
Laravel Unique Validation on U...

Today in this post we will see laravel unique validation on update. unique validation rule in laravel is used when...

Read More


jQuery Show and Hide Effects Example
jQuery Show and Hide Effects E...

Hello friends, in this tutorial, we will see jQuery show and hide effects example. jQuery show method and jQuery...

Read More


How To Validate 10 Digit Mobile Number Using Regular Expression
How To Validate 10 Digit Mobil...

In This small tutorial, I will explain to you how to validate a 10-digit mobile number using regular expressions in...

Read More