Laravel WhereNotIn query method is opposite method of WhereIn query method. When you want to get records in which specified field value is not from given array. Laravel whereNotIn() method uses SQL WHERE NOT IN statement.
In this tutorial, we are going to see Laravel whereNotIn eloquent query method example. This method compares field value with given array. Laravel whereNotIn() method works well with Eloquent as well as query builder. Let's see both example for whereNotIn() method. Laravel whereNotIn method works well in get(), update() or delete() method.
In this example, we will use User model to get users which doesn't have ids from given array.
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
$users = User::whereNotIn('id', [1, 3, 5])
->get();
dd($users);
}
In this example, we will use DB facade to return users which doesn't have ids from given array.
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
$users = \DB::table('users')
->whereNotIn('id', [1, 3, 5])
->get();
dd($users);
}
I hope it will help you.
Hi, My name is Harsukh Makwana. i have been work with many programming language like php, python, javascript, node, react, anguler, etc.. since last 5 year. if you have any issue or want me hire then contact me on [email protected]
Create FTP Client and Connect to Server in Cpanel
cPanel is a web hosting control panel so...How To Create Simple Hello World Application In Node.js
Node Js one of the fastest-growing progr...Difference between private, public, and protected modifiers in PHP
If you have worked in object orient prog...Install Nginx HTTP server on Ubuntu
Nginx is an open source HTTP web server...Laravel Livewire CRUD Tutorial
Hello Artisan Today i am coming with...