Laravel-how to get last week data in laravel

get last week data in laravel

In this blog, we will learn about how to get last week data in laravel, This tutorial will give you a simple example of getting last week’s data in laravel. if you want to see an example of how to get last week’s data in laravel then you are in the right place. Follow bellow tutorial step of laravel 8 gets last week’s records from the database.

In this article, you will learn about wherebetween and carbon function. If you want to see what all carbon does then you can check this link.

By using the below code you can get last week’s data in laravel by using the laravel eloquent method.

$users = User::whereBetween(
                [Carbon::now()->subWeek()->startOfWeek(), Carbon::now()->subWeek()->endOfWeek()]

I hope now you understand how we can get week-wise data in Laravel.

5 1 vote
Article Rating

Please click on advertisment 🙏,helps to maintain website cost
Do you want to hire us for your Project Work? Then Contact US.
Notify of
Inline Feedbacks
View all comments
Would love your thoughts, please comment.x