Laravel Eloquent “WhereNotIn” Query Example

This tutorials will learn to you example of where not in laravel query builder. i will write simple and easy way to understanding for where not in query in laravel eloquent. it is very easy example of wherenotin in laravel web application. you can see following where not in in laravel eloquent as well as orwhere in laravel.

Eloquent WhereNotIn Query Use in Laravel

If you required to use sql wherenotin query in laravel any version then you can use with simple array. Laravel supports wherenotin() to use sql wherenotin query builder. in wherenotin() i just required to pass main two argument one is column name as well as second if array of ids or anything that you want.

Read Also:  Laravel 6 WhereNotIn Query Example

You can display following syntax on wherenotin query in laravel:

whereNotIn(Coulumn_name, Array);

Now i will give you main 3 types of the great example of how to use wherenotin query builder in laravel web application. Therefor let’s bellow display those example how it works.

Simple SQL Query:

SELECT * FROM products WHERE id NOT IN (120, 152, 185) 

Example 1: Laravel Query:

public function index()
{
    $products = User::select("*")
                    ->whereNotIn('id', [120, 152, 185])
                    ->get();
 
    dd($products);                    
}

Also Read: Laravel 6 WhereNotIn Query Example

Read Also:  html starter template bootstrap code for homepage

Example 2: laravel wherenotin query example

Here is second example of wherenotin query builder. You can work with here simple comma separated string value. you can work as like following good Example:

public function index()
{
    $allIds = '125,586,986';
    $productIds = explode(',', $allIds);
    
    $products = User::select("*")
                    ->whereNotIn('id', $productIds)
                    ->get();
  
    dd($products);                    
}

Example 3: wherenotin in laravel query builder

public function index()
{
    $products = DB::table('products')
                    ->whereNotIn('name', ['Mobile', 'Laptop', 'LEDTV'])
                    ->get();
  
    dd($products);                    
}

About Pakainfo

I am Jaydeep Gondaliya, a software engineer, the founder and the person running Pakainfo. I'm a full-stack developer, entrepreneur and owner of Pakainfo.com. I live in India and I love to write tutorials and tips that can help to other artisan, a Passionate Blogger, who love to share the informative content on PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.

View all posts by Pakainfo →

Leave a Reply

Your email address will not be published. Required fields are marked *