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(
                'created_at',
                [Carbon::now()->subWeek()->startOfWeek(), Carbon::now()->subWeek()->endOfWeek()]
            )->get();

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

5 1 vote
Article Rating

Do you want to hire us for your Project Work? Then Contact US.
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x