mardi 8 octobre 2019

How do I return a collection of dates part of timestamp

I have checked around but can't seem to find a solution to this, which is why I'm asking for help here. I am working on a project with Laravel 5.8. I have a mysql table storing customer's orders. The orders table have among other columns ID, order No and a created_at column storing the timestamp of the order. Now I want to return a collection that contains all the dates there are orders and possibly the number of orders for those dates, returned just once like so; 7/10/2019 - 5 6/10/2019 - 6 5/10/2019 - 12 4/10/2019 - 9 I want only the date part of the timestamp of the days when there are orders. The days without orders should be skipped. I have done this;

Order::selectRaw('Date(created_at) as date')->groupBy('date')->get();

But keep getting only today's date.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire