In this article, We will explain to you how to use whereBetween query in laravel(laravel eloquent WhereBetween query example). here we will give you a simple example of laravel eloquent wherebetween() method.

The laravel eloquent provides many types of eloquent methods. The whereBetween method will return the data column’s value between two values like a check between two dates.

Example 1

<?php
   
namespace App\Http\Controllers;
    
use Illuminate\Http\Request;
use App\Student;
  
class StudentController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        $student_detail = Student::select("*")
                        ->whereBetween('marks', [1, 100])
                        ->get();
  
        dd($student_detail);
    }
}

Example 2

<?php
  
namespace App\Http\Controllers;
  
use Illuminate\Http\Request;
use App\Student;
use Carbon\Carbon;
  
class StudentController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        $start = Carbon::now()->subDays(30);
        $end = Carbon::now();
  
        $student_detail = Student::select("*")
                        ->whereBetween('created_at', [$start, $end])
                        ->get();
  
        dd($student_detail);
    }
}