How to create date to date search query in laravel?

by dalton_moen , in category: PHP Frameworks , 5 months ago

How to create date to date search query in laravel?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by rollin , 5 months ago

@dalton_moen 

To create a date to date search query in Laravel, you can use the whereBetween method provided by Laravel's Eloquent ORM. Here's an example of how you can create a date to date search query:

1
2
3
4
5
6
$start_date = '2022-01-01';
$end_date = '2022-01-31';

$data = Model::whereBetween('created_at', [$start_date, $end_date])->get();

return $data;


In this example, replace Model with the name of your Eloquent model and created_at with the name of the column you want to search by. $start_date and $end_date represent the date range you want to filter by.


This query will retrieve all records where the created_at column falls within the specified date range. You can modify this query as needed to fit your specific requirements.