Calling populate method in own endpoint

Hello
I have a next post.php file
<?php

$cat = $this->param(‘cat’);
$post = $this->param(‘post’);

if (!$cat || !$post) {
echo “Not found post or cat params…”;
return “Not found post or cat params…”;
}

$entries = cockpit(‘collections’)->find(‘post’, [
‘filter’ => function($document) use ($cat, $post) {
if ($document[‘url’] === $post){
foreach((array)$document[‘category’] as $item) {
if ($item[‘display’] === $cat) return true;
}
}

        return false;
    }
]);

$populated_entries = cockpit('collections')->populate('post', $entries)->toArray();

echo "<script>console.log(".json_encode($populated_entries).")</script>";
return $entries;

It is used to find all post by postUrl and catUrl. (Post can have more categories)
In $entries I have all post by postUrl and catUrl. (Post can have more categories);
Now I need to “expand” all collection Links (populate). I try to do it and save results to $populated_entries variable. But it doesn;t work

What do I wrong?
Thanks

I have already solve it.

Just add ‘populate’=>1

Here is full code

<?php
include_once 'cockpit/bootstrap.php';

$cat = $this->param('cat');
$post = $this->param('post');

if (!$cat || !$post) {
    echo "Not found post or cat params...";
    return "Not found post or cat params...";
}

$entries = cockpit('collections')->find('post', [
    'filter' => function($document) use ($cat, $post) {
        if ($document['url'] === $post){
            foreach((array)$document['category'] as $item)  {
                  if ($item['display'] === $cat)  return true;
            } 
        }
    

        return false;
    },
    'populate' => 1
]);

//$populated_entries = cockpit('collections')->populate('post', $entries)->toArray();

echo "<script>console.log(".json_encode($entries).")</script>";
return $entries;

Guys, you have great CMS. It looks awesome and your community is also good, but Documentation… It’s really hard to find the answer to question .:frowning:
However, thank you for cockpit