How to Get Last Week Data in Laravel 7/6 ?

10-Apr-2023

.

Admin

Hi Guys,

Today, I will teach you how to get last week records in laravel 7/6 using Carbon. We will carbon for select last week data in laravel 7/6 eloquent query.

In this blog, We will learn about selecting all records created last week with Carbon in an example. There are the following the simple example into get last 7 days records in laravel 6.

Example


public function getData()

{

$date = \Carbon\Carbon::today()->subDays(7);

$users = User::where('created_at','>=',$date)->get();

dd($users);

}

Output

Collection {#309

#items: array:4 [

0 => User {#310 }

1 => User {#311 }

2 => User {#312 }

3 => User {#313 }

]

}

It will help you...

#Laravel 7

#Laravel

#Laravel 6