
laravel eloquent WhereBetween query example
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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | <?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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | <?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); } } |