Laravel Eloquent whereNotBetween() Example
In this tutorial, we will learn Laravel Eloquent whereNotBetween() Example. we will help you to give an example of Laravel whereNotBetween() eloquent. We use Laravel its own eloquent whereNotBetween() query to get dates-wise data from a database table. whereNotBetween() query will help you to get data with not between two dates or two values from the database table in the Laravel application. and we create also Laravel Eloquent whereNull() and whereNotNull() Query tutorial.
I would like to share Laravel Eloquent whereNotBetween() Example. In this tutorial, you will learn Laravel Eloquent whereNotBetween() Example.
Also read: Laravel Eloquent whereNull() and whereNotNull() Query
In this example, we will a very simple example of how to use whereNotBetween() in the Laravel application.
SQL Query:
select * from `users` where `age` not between ? and ?
Laravel Query:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\User;
class UserController extends Controller {
public function index() {
$users = User::select("*")->whereNotBetween('age', [1, 16])->get();
dd($users);
}
}
SQL Query:
select * from `users` where `created_at` not between ? and ?
Laravel Query:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\User;
use Carbon\Carbon;
class UserController extends Controller {
public function index() {
$startdate = Carbon::now()->subDays(30);
$enddate = Carbon::now();
$users = User::select("*")->whereNotBetween('created_at', [$startdate, $enddate])->get();
dd($users);
}
}