I have a bunch of ToDo items, some of which are recurring. The same task may have a due_date every week/month/quarter etc. I'm tracking recurring ToDo items with a recurring_identifier_id. E.g. the January and February version of a ToDo task of would have the same recurring_identifier_id to link them.
I want to query the database to get all of the unique (recurring_identifier_id) with the due_date most in the future.
$collection = TodoItems::select('*')
->having('user_id', '=', $userId)
->groupBy('recurring_identifier_id')
->get();
The above query gets unique ToDo items with groupBy('recurring_identifier_id'). How can I make sure that for e.g. 10 ToDo items with the same recurring_identifier_id, that I grab the one with the due_date most in the future?
I haven't done a where clause to get ToDo items with a due_date between certain dates (e.g. start and end of month) as ToDo items could be monthly, quarterly, etc.