get entries from last month, day by day

Published 4 months ago by jaheller

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?

jaheller

bump.

topvillas

What have you tried so far?

jaheller

@topvillas

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.

topvillas

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.

jaheller

Could you show me an example for the order process. The rest is nothing new to me.

topvillas

Just use the orderBy function

jaheller

@topvillas

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.