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

How to install Adminer in Laravel application


In this article we will install Adminer in Laravel 8 application

Crop Image Before Upload Using Croppie.js in Laravel 9


Using Laravel 9, crop an image before uploading it using Croppie.js. Before uploading an image, Laravel uses Ajax to crop it with croppie. Cropping an...

Laravel Query Builder Where Exists Example


laravel use sql where exists clause,laravel whereExists, laravel whereExists not working,laravel where exists example,laravel exists query

Laravel 8 Clear Cache of Route, View, Config Command Example


laravel 8 clear cache, laravel 8 clear cache config, laravel 8 cache clear view, laravel 8 cache clear config, laravel 8 cache clear command

Laravel 9 Highcharts Example Tutorial


In this tutorial, I'll give you an example of how to use highchart js to construct a highchart in a laravel 9 application.