Laravel Eloquent whereNotBetween() Query Example

By Hardik Savani | July 24, 2020 | 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 and laravel 8 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...




Hardik Savani
My name is Hardik Savani. I'm a full-stack developer, entrepreneur and owner of Aatman Infotech. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.
Follow Me: Github Twitter
***Do you want me hire for your Project Work? Then Contact US.

We are Recommending you: