Laravel Eloquent whereNotBetween() Query Example

By Hardik Savani April 16, 2024 Category : Laravel

This tutorial will give you example of laravel where not between eloquent. we will help you to give example of laravel eloquent whereNotBetween. you will learn laravel eloquent whereNotBetween dates. Here you will learn laravel whereNotBetween dates example. Alright, let’s dive into the steps.

whereNotBetween() will help you to getting data with not between two dates or two values from database in laravel 6, laravel 7, laravel 8, laravel 9, laravel 10 and laravel 11 application.

In this example i will give you very simple example of how to use whereNotBetween in laravel application. you can easily use it with laravel 6 and laravel 7 application.

So, let's see bellow examples that will help you how to use whereNotBetween() eloquent query in laravel.

Example 1:

SQL Query:

select * from `users`

where `points` not between ? and ?

Laravel Query:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\User;

class UserController extends Controller

{

/**

* Display a listing of the resource.

*

* @return \Illuminate\Http\Response

*/

public function index()

{

$users = User::select("*")

->whereNotBetween('points', [1, 100])

->get();

dd($users);

}

}

Example 2:

SQL Query:

select * from `users`

where `created_at` not between ? and ?

Laravel Query:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\User;

use Carbon\Carbon;

class UserController extends Controller

{

/**

* Display a listing of the resource.

*

* @return \Illuminate\Http\Response

*/

public function index()

{

$start = Carbon::now()->subDays(30);

$end = Carbon::now();

$users = User::select("*")

->whereNotBetween('created_at', [$start, $end])

->get();

dd($users);

}

}

I hope it can help you...

Shares