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

Unlocking the Power of Data Visualizing Laravel App Data with Chartello


Discover the potential of data visualization with Chartello, a Laravel app that helps you unlock insights from your data. Try it now and see the resul...

Laravel 9 Stripe Payment Gateway Integration Example


Stripe payment gateway for Laravel 9; I'll demonstrate how to include Stripe payment gateway into Laravel 9 apps in this tutorial.

How to inline row editing using Laravel 9


Learn how to implement inline row editing in Laravel 9 with our step-by-step guide. Make editing data faster and more efficient on your website.

Laravel 8 Generate PDF File using DomPDF | Laravel 8 PDF


How to generate pdf from view, html, blade in laravel 8. Here, we would share with you how to generate pdf file from blade view in laravel 8

Laravel One to Many Polymorphic Relationship


laravel polymorphic relations example, laravel polymorphic one to many, laravel eloquent polymorphic relations, laravel one to many polymorphic