Laravel where not between query example; In this tutorial, you will learn how to use whereNotBetween eloquent query in laravel. The whereNotBetween method verifies that a column’s value lies outside of two values.
If you fetch some data from database in laravel and you may want to leave some data between two column values. In that case you can use laravel eloquent whereNotBetween cluase.
laravel whereNotBetween() will help you to getting data with not between two dates or two values from database. You can easily use these example in laravel 5, laravel 6, laravel 7, laravel 8 or laravel 9 application.
Example 1:
use App\Models\User;
public function index()
{
$users = User::whereNotBetween('id', [1, 5] )
->get();
dd($users);
}
Example 2:
use App\Models\User;
public function index()
{
$users = User::whereNotBetween('created_at', [2020-06-10, 2020-07-20])
->get();
dd($users);
}
Example 3:
use App\Models\User;
public function index()
{
$startDate = Carbon::now()->subDays(30);
$endDate = Carbon::now();
$users = User::whereNotBetween('created_at', [$startDate , $endDate ])
->get();
dd($users);
}
I hope these example help you…