In this model, we will see the Laravel whereIn and whereNotIn query model. By using Laravel query builder we can use different types of query to sort or filter data from data tables.
Now let?s see how we can use Laravel whereIn and whereNotIn query methods.
Laravel whereIn accepts array as input, so whereIn method filters/ verifies data from assign array in the given column?s.
whereIn(Coulumn_name, Array)
Laravel whereNotIn accepts array as input, so whereNotIn method filters/ verifies data from excluding given array in the assign column?s.
whereNotIn(Coulumn_name, Array)
SQL Where IN Query Example
SELECT * FROM users WHERE user_id IN (4,5,6)
Laravel whereIn Query
public function index()
{
$students = Users::select("*")
->whereIn('user_id', [4,5,6])
->get();
}
SQL Where NOT IN Query Example
SELECT * FROM users WHERE user_id NOT IN (4,5,6)
Laravel whereNotIn Query
public function index()
{
$students = Users::select("*")
->whereNotIn('user_id', [4,5,6])
->get();
}
I hope you will like the content and it will help you to learn whereIn and whereNotIn Query Example in Laravel
If you like this content, do share.