In this model, we will see the Laravel whereIn and whereNotIn query model. By using Laravel query builder we can use different types of query to sort or filter data from data tables.

Now let?s see how we can use Laravel whereIn and whereNotIn query methods.

Laravel whereIn accepts array as input, so whereIn method filters/ verifies data from assign array in the given column?s.

whereIn(Coulumn_name, Array)


Laravel whereNotIn accepts array as input, so whereNotIn method filters/ verifies data from excluding given array in the assign column?s.

whereNotIn(Coulumn_name, Array)


SQL Where IN Query Example

SELECT * FROM users WHERE user_id IN (4,5,6)


Laravel whereIn Query

public function index()
{
   $students = Users::select("*")
               ->whereIn('user_id', [4,5,6])
               ->get();
}


SQL Where NOT IN Query Example

SELECT * FROM users WHERE user_id NOT IN (4,5,6)


Laravel whereNotIn Query

public function index()
{
   $students = Users::select("*")
               ->whereNotIn('user_id', [4,5,6])
               ->get();
}

I hope you will like the content and it will help you to learn whereIn and whereNotIn Query Example in Laravel
If you like this content, do share.


Recommended Posts

View All

Laravel Where Clause with MySQL Function Example


laravel eloquent where year,laravel eloquent mysql functions,laravel eloquent where clause mysql,mysql function mysql laravel

Laravel 9 Image Resize & Upload with Intervention Image


This tutorial will show you how to use the PHP intervention image package to resize an image in a Laravel application.

Laravel 9 Scout Full Text Search with Algolia Tutorial


A full-text search feature in a web application is incredibly useful for users to navigate through content-rich web and mobile applications, as demons...

Laravel 9 Dropzone Image Upload Example Step By Step


The most well-known, free, and open-source library for drag-and-drop file uploads with image previews is Dropzone. I'll be using Laravel 9 in...

Laravel 8 Generate PDF with Graph Tutorial


Laravel 8 generates a graphed pdf. You will understand how to generate a pdf with a graph in the Laravel 8 app in this tutorial