Laravel whereNotIn Eloquent Query Example

Laravel where not in query example tutorial. Here, you will learn how to use laravel whereNotIn() eloquent method to implementing a query with eloquent model and query builder in laravel.

This tutorial provides you simple examples of where Not In Laravel Query Builder. And as well as how to use Laravel Eloquent WhereNotIn with arrays.

Suppose you want to skip some records when fetching records from the database table. For e.g. you have a users table and you do not want to get records whose user id’s 10, 15, 18. So you can use the eloquent WhereNotIn() method with a query.

The following syntax represents the whereNotIn eloquent method in laravel:

whereNotIn(Coulumn_name, Array);


  • Column_name:- Your database table column name.
  • Array: – Column’s value is not contained in the given array.

Let’s take look at some example of whereNotIn() eloquent method in laravel:

Example 1: whereNotIn Query Using Simple SQL Query:

SELECT *  FROM users  WHERE id NOT IN (10, 15, 18) 

In this SQL query, the data will not be get from the DB table. Whose ids will be 10, 15, 18.

Example 2: Eloquent WhereNotIn Query Using Query Builder

public function index()
    $data = DB::table('users')
                ->whereNotIn('id', [10, 15, 18])

Example 3: Eloquent WhereNotIn Query Using Laravel Model

public function index()
    $data= User::whereNotIn('id', [10, 15, 18])->get();

So far you have seen in the given example. Have used ids for scaping and getting data into db table. But now for example 4, we will fetch the data by using the DB table column name.

Example 4: Eloquent WhereNotIn Query Using Laravel Model With Different Column Name

public function index()
    $data= User::whereNotIn('name', ['john','dam','smith'])->get();


In this where not in laravel query example, you have learned how to use laravel whereNotIn() eloquent method to implemeting a queries in laravel with eloquent model and query builder.

Recommended Laravel Posts


My name is Devendra Dode. I am a full-stack developer, entrepreneur, and owner of I like writing tutorials and tips that can help other developers. I share tutorials of PHP, Python, Javascript, JQuery, Laravel, Livewire, Codeigniter, Node JS, Express JS, Vue JS, Angular JS, React Js, MySQL, MongoDB, REST APIs, Windows, Xampp, Linux, Ubuntu, Amazon AWS, Composer, SEO, WordPress, SSL and Bootstrap from a starting stage. As well as demo example.

Leave a Reply

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