ItSolutionStuff.com

Laravel Eloquent whereNotBetween() Query Example

By Hardik Savani β€’ April 16, 2024
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...

Hardik Savani

Hardik Savani

I'm a full-stack developer, entrepreneur, and founder of ItSolutionStuff.com. Passionate about PHP, Laravel, JavaScript, and helping developers grow.

πŸ“Ί Subscribe on YouTube

We Are Recommending You

β˜…

Laravel Eloquent whereRaw Condition Example

Read Now β†’
β˜…

Laravel Eloquent Where Query Examples

Read Now β†’
β˜…

Laravel Eloquent orWhere() Condition Example

Read Now β†’
β˜…

Laravel Multiple Where Condition Example

Read Now β†’
β˜…

Laravel Eloquent WhereNotIn Query Example

Read Now β†’
β˜…

Laravel Relationship Eager Loading with Condition Example

Read Now β†’
β˜…

Laravel Relationship Eager Loading with Count Example

Read Now β†’
β˜…

Laravel Many to Many Eloquent Relationship Tutorial

Read Now β†’
β˜…

Laravel WhereIn() and WhereNotIn() with Subquery Example

Read Now β†’
β˜…

Laravel Where Condition with Two Columns Example

Read Now β†’
β˜…

Laravel Where Clause with date_format() Example

Read Now β†’
β˜…

Laravel Eloquent Where Like Query Example Tutorial

Read Now β†’