Following up on my previous article on https://chasingcode.dev/blog/mysql-cte-group-by-year-month-with-gaps/, I am offering an implementation of the same technique in Laravel. Note This requires MySQL v8.0+.

There's a Laravel package for everything, and CTEs are no exception.

Here's how this looks in Laravel: $user_id = 1; $bike_id = 100; $bindings = [$user_id, $bike_id, $user_id, $bike_id, $user_id, $bike_id]; $query = " date ) AS ( DATE(LAST_DAY(MIN(start_date))) rides user_id = ?

I hope Laravel will have first class support for Common Table Expressions at some point in the future, but for now these two techniques should suffice.
Newsletter

Get the latest Laravel/PHP jobs, events and curated articles straight to your inbox, once a week

Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge. Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge.
Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Shirts painstakingly handcrafted by under-caffeinated developers. Shirts painstakingly handcrafted by under-caffeinated developers.
Community Partners