toPages() throws error on pages field

Hi everyone,

I am running into a problem with a pages field and just can’t figure out what I am doing wrong.

I have a pages field which looks like this:

filters:
  type: pages
  label: Filter
  query: page.siblings.template('filtercategories').children.children
  text: "{{page.parent.title}}: {{page.title}}"
  image: false

Everything works great, but now I would like to use the selected pages to output there data.
I use kirby headless, and when I do
$page->filters() it returns
"value":"- 'page://JSbhooZBUnKD5YOn'\n- 'page://MlM0QADBzmcZltsM'\n- 'page://BzAzENuWPvJ0C9qf'\n- 'page://FJ5sXLcImFgmuHHu'"

However, when i try $page->filters()->toPages() to later use a map function to access the data, I get a “Call to a member function children() on array” error. How am I supposed to access the data of the pages field?

I am grateful for any hints!

This is correct, and I don’t think this is the line of code that causes the error. So more context would be helpful

I narrowed the problem down a bit. I hope I can explain it because it has something to do with my specific file structure.

I have a couple of pages where the filters field is used.
When calling 'filters' => $page->filters()->toPages() on one of the pages, it does indeed provide the right results, e.g. output like this:

"filters":{"data":{"materialien/filtercategories/typ/datei":{"blueprints":null,"content":null,"translations":null,"children":null,"drafts":null,"childrenAndDrafts":null},"materialien/filtercategories/grosse/mittel":{"blueprints":null,"content":null,"translations":null,"children":null,"drafts":null,"childrenAndDrafts":null}

However, when I move over to the parent of these pages and try to call the filters, the above error shows up.
My php looks like this:

'materials' => $page
    ->children()
    ->template('material')
    ->listed()
    ->map(fn ($material) => [
        'filters' => $material->filters()->toPages()
    ])->values()

If I remove ->toPages() it gives this output: "filters":{"value":"- 'page://C5R0rXsHvTGANvRr'"}

Does this make the issue clearer?