Laravel-how to 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.

Shaiv Roy

Hy Myself shaiv roy, I am a passionate blogger and love to share ideas among people, I am having good experience with laravel, vue js, react, flutter and doing website and app development work from last 7 years.

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Check Also
Back to top button