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.
$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.
select * from `Register` where `rollno` between ? and ?
<?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);
}
}
Are you a blogger who expresses his thoughts with the help of words? If yes, then you might have once thought to create...
Nov-13-2023
In this tutorial, we will see laravel 9 form validation example. For any incoming data, we need to validate i...
Feb-12-2022
In this example we will see autocomplete search using bootstrap typeahead js.Typeahead search is a method for progr...
Jun-09-2021
Laravel is a popular PHP framework known for its elegance and simplicity in building web applications. When it comes to...
Sep-13-2023