In this post, you will learn how to get last 7 days records in laravel using carbon. we will carbon for select last 7 days data in laravel 5 eloquent query.
Actually, i love to share everything related to laravel. whenever i am developing on my laravel application, i note all the small issue that fetch and note solution so i can write small post and someone can sole out his issue too.
Currently, i was working on my laravel 5.6 application and i require to get last 30 days records from database table. i am working on laravel from long time so i know i can get last 30 days records from Carbon. So basically if you have also need to get last 7 days records then you can do it like as bellow solution.
Get Last 7 days records in Laravel
$date = \Carbon\Carbon::today()->subDays(30);
$users = User::where('created_at', '>=', $date)->get();
dd($users);
I hope it can help you...
Do you like below Tutorials ?
- Laravel 5.6 - Collection could not be converted to int
- Laravel - How to generate secure https URL from route?
- Laravel - Vue JS File Upload Example
- How to get last 7 days data in Laravel?
- Laravel Validation required if other field empty example
- Laravel Eloquent - When Case Statement in Select Query Example
- Laravel 7.x and 6.x Passing Variable to Javascript Example
- How to pass PHP variables in JavaScript or jQuery?