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();
I hope it can help you...
Do you like below Tutorials ?
- Laravel generate random unique string example
- Laravel - chmod(storage/oauth-private.key): Operation failed: Operation not permitted
- Laravel 7.x and 6.x datatables example from scratch
- How to compress PNG image using pngquant in PHP?
- Laravel 7.x and 6.x Chart example using Charts Package
- Guzzle http client GET and POST request example in Laravel 5
- Laravel schema default current timestamp value example
- Laravel 7.x and 6.x Get Site URL Examples