In this article, I will demonstrate a Laravel whereBetween query example. SQL offers various methods and queries to retrieve filtered data from a database. In this post, we will explore the Laravel orWhereBetween query builder example.
We'll dive into a Laravel whereBetween dates example and also cover the use of Laravel's orWhereBetween SQL query alongside Laravel's query builder.
Let's get started laravel 8/9/10 whereBetween and orWherebetween example.
Now I will show you an example of the whereBetween() query in laravel 8/9/10 and how to write the whereBetween() condition in laravel.
$students = DB::table('Register')
->whereBetween('RollNo', [1, 50])
->get();
So first, we will see SQL query for better understanding.
select * from `Register` where `rollno` between ? and ?
We will get records between two dates with the help of whereBetween in laravel 8/9/10.
<?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);
}
}
In conclusion, we've explored the powerful whereBetween method in Laravel. These methods provide a flexible way to retrieve data from the database based on a specified range, making it a valuable tool in your Laravel development journey.
Whether you're working with date ranges, numerical intervals, or any other field, the whereBetween queries offer an efficient and elegant solution to filter your data effectively.
You might also like: