Published 1 month ago
What's the best way to get all records from the last month, day by day using the default laravel "created_at" as timestamp of creation.
Is there some way to prevent needless database load, when loading them?
What have you tried so far?
I used a while loop to query each day by day over the last month, but I'm sure there's a better way to do so.
Use Carbon to create two dates that are the start and end of the last month.
Query your model where created_at is between the dates and order them using the created_at date.
Could you show me an example for the order process. The rest is nothing new to me.
Just use the orderBy function
But how to 'group' them since I only want to display for example the sum of each day?
Please sign in or create an account to participate in this conversation.