How to Get Last 30 Days Data in Laravel ?

Laravel 6 , Laravel

Nicesnippets

625

14-12-2019


Hi Guys,

Today, I will teach you how to get last 30 days records in laravel using Carbon. We will carbon for select last month data in laravel eloquent query.

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

Example

public function getData()

{

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

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


Recommended Posts