HDTuto.com

How to get last 7 days data in Laravel?


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...




August 8, 2018 | Category : PHP Laravel
Related Posts