I get the issue, using a dynamic property which is likely leading to the issue. I suspect I need to be more specific now on what $event->year actually is but not sure how.
Probably didn’t show enough context, here is all of the relevant code.
// Collect all of the unique years to create the horizontol menu bar to make year selection easier.
$events = $page->grandchildren()
->filterby('timeline_date', 'date >=', '1933-01-01')
->filterby('timeline_date', 'date <=', '1945-12-31');
$events = $events->map(function($event) {
$event->year = $event->timeline_date()->toDate('Y');
return $event;
});
$years = $events->pluck('year', ',', true);
// return unqiue years and relevant events.
return compact('first_events', 'years');
I can only repeat what I wrote above. Create a page model for the $event page (the name of the model depends on the blueprint used for these grandchildren pages) and define a $year property.
modern php does not allow creating properties on the fly anymore. like suggested you need a page model and for that class define the $year property before using your code above.
Ok, thanks will have a look at that. I guess I thought there was a simpler way to solve this in the controller than having to create a model just for this.
I am such a complete idiot sometimes. Why make it easy with a couple of lines of code when you can overcomplicate it unnecessarily? I knew I was making a total hash of it and searching way too many records just to get the years.