How can I filter a structure object?

Hi there!

I am trying to use the filter method on a structure object. It is a structure field of dates (including a date, a time and an info field).

$pastDates = $block->dates()->toStructure()->sortBy('date')->filter(function ($structureItem) {
  return $structureItem->date()->toDate() < time();

I expect to receive a filtered list of structure items. But when I try to dump the result, I get something like this:

Kirby\Cms\Structure Object
    [0] => 0
    [1] => 1

I have no idea what went wrong, but I cannot access the dates anymore it seems? Can somebody please help me how I can use the filter method correctly?



That’s totally ok, if you dump the unfiltered structure object, it looks the same, use toArray() to see what you got;


Aha! Now that was easy – if only I knew what to do. :wink:

Thanks. Is there any better way to “inspect” a structure object directly? So I can see what sort of info is stored inside?