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.
-
Have you tried running the sql query directly against the database? Are you sure it works doing
groupBy('date')
using the alias, maybe you needgroupBy('Date(created_at)')
? – Joakim Danielson 1 hour ago -
Yes @Joachim. It however returns a collection of the orders with today's date as date for all of them – banky 1 hour ago
-
0 Comments
Thanks for comment.