# Calling populate method in own endpoint

**URL:** <https://discourse.getcockpit.com/t/calling-populate-method-in-own-endpoint/951>\
**Category:** Support\
**Created:** [July 29, 2019, 7:45pm UTC](https://discourse.getcockpit.com/t/calling-populate-method-in-own-endpoint/951 "2019-07-29T19:45:24Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![YuriiLeso](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/yuriileso/32/462_2.png) [@YuriiLeso](https://discourse.getcockpit.com/u/YuriiLeso)\
**Post date:** [July 29, 2019, 7:45pm UTC](https://discourse.getcockpit.com/t/calling-populate-method-in-own-endpoint/951/1 "2019-07-29T19:45:24Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![YuriiLeso](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/yuriileso/32/462_2.png) [@YuriiLeso](https://discourse.getcockpit.com/u/YuriiLeso)\
**Post date:** [July 29, 2019, 8:16pm UTC](https://discourse.getcockpit.com/t/calling-populate-method-in-own-endpoint/951/2 "2019-07-29T20:16:53Z")

</div>

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 .☹  
However, thank you for cockpit
