Support the ongoing development of Laravel.io →
Database Eloquent
Last updated 2 years ago.
0

If you're querying a month at a time, and you know what month you are querying for, you could use Carbon within the where clause

(untested)

$augustRecords = EventModel::where(Carbon::createFromFormat('Y-m-d', '2015-08-01')->startOfMonth())->where(Carbon::createFromFormat('Y-m-d', '2015-08-01')->endOfMonth())->get();

If you want a recordset with multiple months and be able to group them, you could convert the date to a string containing the month and year within the SQL and group based on that - retaining all records, but allowing you to order/sort using SQL and output with any grouping you'd need.

Last updated 9 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.