Home » Laravel Eloquent “WhereNotIn” Query Example

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:  how to call javascript function in html & JavaScript Define

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:  Eloquent orwhere Query Use in Laravel

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);                    
}


Related FAQ

Here are some more FAQ related to this Article:

  1. Read Also:  8 Useful PHP Tips Tricks and Best Practices
  2. Read Also:  Google Style Text Avatar using PHP Example
  3. Read Also:  SQL SELECT SUM on multiple INNER JOIN with another table
  4. Read Also:  Laravel 6 WhereNotIn Query Example
  5. Read Also:  jQuery Check if Element Exists Example
  6. Read Also:  Install WhatsApp web On iPad Without iPhone Tutorials
  7. Read Also:  AJAX Pagination with Laravel Example From Scratch
  8. Read Also:  PHP Autocomplete search with typeahead.js
  9. Read Also:  Remove null values from array in PHP
  10. Read Also:  Mysql update query statement with example

Leave a Comment

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