Laravel 8 Wherenotin Eloquent Query Example

Share Me
  •  
  •  
  •  
  • 1
  •  
  •  
  •  
  •  
  •  
  •  
  •  
    1
    Share
Laravel 8 Wherenotin Eloquent Query Example

Today now in this example,I will show you how to use wherenotin query in laravel 8 application. We can simply use to wherenotin query in our controller.

So we may sometimes need to use select query with where not in clause. Now we can simply make query by using MySQL.

For example,we have table 5 record in 3 record not get that define to wherenotin query in your contoller.

So we will check this wherenotin query in our controller. Just need to follow bellow example

Example 1 :

/**
* The attributes that are mass assignable.
*
* @var array
*/
public function index()
{
    $users = User::whereNOTIn('id',[1,2])->get();

    dd($users);
}

Example 2 :

/**
* The attributes that are mass assignable.
*
* @var array
*/
public function index()
{
    $users = DB::table('users')
                ->whereNOTIn('id', [1, 2])
                ->get();

    dd($users);
}
Example 3 :
/**
* The attributes that are mass assignable.
*
* @var array
*/
public function index()
{
    $myArray = ["jaydev","sunil","kanak"];

    $users = User::whereNOTIn('name',$myArray)->get();

    dd($users);
}

Read Also : Laravel 8 Eloquent Global Scope Tutorial Example

I hope it will help you. Also you can follow us on Facebook

About Shahriar Sagor

My name is Shahriar sagor. I'm a developer. I live in Bangladesh and I love to write tutorials and tips that will help to other Developer's. I am a big fan of PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.

View all posts by Shahriar Sagor →