Laravel WhereNotIn Query Example
This article will provide you example of where not in laravel query builder. we will write where not in query in laravel eloquent. it is very simple example of wherenotin in laravel application. you can see bellow where not in in laravel eloquent.
you can simple use wherenotin eloquent method in laravel 6, laravel 7, laravel 8 and laravel 9.
If you need to use sql wherenotin query in laravel then you can use with array. Laravel provide wherenotin() to use sql wherenotin query. in wherenotin() we just need to pass two argument one is column name and another if array of ids or anything that you want.
You can see bellow syntax on wherenotin query in laravel:
whereNotIn(Coulumn_name, Array);
Now i will give you three example of how to use wherenotin query in laravel application. So let's see those example how it works.
Example 1:
SQL Query:
SELECT *
FROM users
WHERE id NOT IN (4, 5, 6)
Laravel Query:
public function index()
{
$users = User::select("*")
->whereNotIn('id', [4, 5, 6])
->get();
dd($users);
}
Example 2:
Here is another example of wherenotin query. You can work with comma separated string value. you can work as like bellow:
public function index()
{
$myString = '1,2,3';
$myArray = explode(',', $myString);
$users = User::select("*")
->whereNotIn('id', $myArray)
->get();
dd($users);
}
Example 3:
public function index()
{
$users = DB::table('users')
->whereNotIn('name', ['Hardik', 'Vimal', 'Harshad'])
->get();
dd($users);
}
I hope it can help you...

Hardik Savani
I'm a full-stack developer, entrepreneur and owner of Aatman Infotech. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Laravel, Angular, Vue, Node, Javascript, JQuery, Codeigniter and Bootstrap from the early stage. I believe in Hardworking and Consistency.
We are Recommending you
- How to Create and Use Query Scope in Laravel Eloquent
- Laravel Eloquent Relationships Tutorial From Scratch
- Laravel Many to Many Eloquent Relationship Tutorial
- Laravel Select with Count Query with Group by Example
- Laravel Select with Sum Query Example
- Laravel Like Query Example using Eloquent Where Clause
- Laravel Join with Subquery in Query Builder Example
- How to Get Query Log in Laravel Eloquent?