If you are looking to get rows created each day for a particular Model in your database, here is how you can achieve this.
For this example, I have a User
model, and I am looking to get the count of users created each day.
User->all()->countBy(function($item) {
return $item->created_at->format('Y-m-d');
});
You can also apply the date range in which you want to get the results
User::where('created_at', '>=', $date_from)
->where('created_at', '<', $date_to)
->get()->countBy(function($item) {
return $item->created_at->format('Y-m-d');
});
Comments