Laravel whereBetween Query Example

Websolutionstuff | Jan-13-2021 | Categories : Laravel PHP

In this article, we will see laravel whereBetween query example. SQL provides many different types of methods or queries to get filtered data from databases. So, in this post, we will learn laravel whereBetween and orWhereBetween query builder examples. In laravel 6, laravel 7, and laravel 8 you can use the whereBetween() and orWhereBetween() functions to get records from a given date range or values.

Here, we will give you the code of laravel whereBetween dates example. In the below code, we have added laravel wherebetween with orwherebetween SQL query as well as Laravel query.

So, let's see the whereBetween query in laravel 7/8 and the whereBetween SQL query example.

Example of whereBetween() condition in laravel

$students = DB::table('Register')
           ->whereBetween('RollNo', [1, 50])
           ->get();

Now I will show you an example of whereBetween() query in laravel 6/7/8 and how to write whereBetween() condition in laravel. So first we will see SQL query for better understanding.

 

SQL OR Example

select * from `Register` where `rollno` between ? and ?

 

get all records between two dates using where between in laravel

<?php
  
namespace App\Http\Controllers;
  
use Illuminate\Http\Request;
use App\Register;
use Carbon\Carbon;
  
class RegisterController extends Controller
{
    public function index(Request $request)
    {
      $names = Register::whereBetween
               ('created_at',[$request->start_date,$request->$end_date])->get();
  
        dd($names);
    }
}

 

Recommended Post
Featured Post
Laravel 8 Socialite Login With GitHub Account
Laravel 8 Socialite Login With...

In this tutorial we will see laravel 8 socialite login with github account. explains how to integrate OAuth github...

Read More

Oct-25-2021

How To Disable Future Date In jQuery Datepicker
How To Disable Future Date In...

In this tutorial, we will see how to disable future dates in jquery datepicker. In the date picker, today's dat...

Read More

Jun-17-2022

How to Add Date Picker in React JS using react-datepicker
How to Add Date Picker in Reac...

A date picker is a crucial component in many web applications, enabling users to select dates conveniently. React, a pop...

Read More

Sep-11-2023

How To Fix cURL Error 60 SSL Certificate Problem
How To Fix cURL Error 60 SSL C...

In this example we see how to fix cURL error 60 SSL certificate problem. cURL error 60: SSL certificate proble...

Read More

Dec-08-2021