How to Get Last 30 Days Data in Laravel ?
Dec 14, 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...
- How to Notifications With database Driver in Laravel 11?
- How to Send Email Via Notification in Laravel 11?
- How to Install and Configure Laravel 11 Debugbar?
- How to Like Dislike System in Laravel 11?
- How to Paginate a Model with Relationship in Laravel 11?
- Laravel 11 Upload Files to Amazon S3 Example
- Laravel 11 Send WhatsApp Messages Example
- Laravel 11 Rest API Authentication Using JWT Tutorial