# \[SOLVED\] Restrict out based on boolean

**URL:** <https://discourse.getcockpit.com/t/solved-restrict-out-based-on-boolean/1339>\
**Category:** Support\
**Created:** [April 8, 2020, 7:25pm UTC](https://discourse.getcockpit.com/t/solved-restrict-out-based-on-boolean/1339 "2020-04-08T19:25:25Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Luca-Castelnuovo](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/luca-castelnuovo/32/559_2.png) [@Luca-Castelnuovo](https://discourse.getcockpit.com/u/Luca-Castelnuovo)\
**Post date:** [April 8, 2020, 7:25pm UTC](https://discourse.getcockpit.com/t/solved-restrict-out-based-on-boolean/1339/1 "2020-04-08T19:25:25Z")

</div>

Hi,

I have a collection with a “visible” boolean switch. I would like to filter the output to only show entries with visible=true.

I know this can be achieved using php code in the blue read permission section.  
But I don’t how to achieve this.

Maybe something like this

```
if( ! $item['visible']) {
    return false;
}

```

Thank you in advance.

---

<div class="post-metadata">

**Author:** ![serjoscha87](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/serjoscha87/32/151_2.png) [@serjoscha87](https://discourse.getcockpit.com/u/serjoscha87)\
**Post date:** [April 9, 2020, 6:02am UTC](https://discourse.getcockpit.com/t/solved-restrict-out-based-on-boolean/1339/2 "2020-04-09T06:02:24Z")

</div>

Why don’t you just use the API in order to filter out entries? Thats what it is made for.

If you want to do it by the read permission try something like

```
<?php
if (isset($context->user) && $context->user['group'] !== 'admin') {
    $context->options['filter']['visible'] = true;
}
```

---

<div class="post-metadata">

**Author:** ![Luca-Castelnuovo](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/luca-castelnuovo/32/559_2.png) [@Luca-Castelnuovo](https://discourse.getcockpit.com/u/Luca-Castelnuovo)\
**Post date:** [April 9, 2020, 7:17am UTC](https://discourse.getcockpit.com/t/solved-restrict-out-based-on-boolean/1339/3 "2020-04-09T07:17:19Z")

</div>

Thank you for the quick response.

The reason why I want to filter server-side is as to not leak unannoucent content.  
If I just used `https://cms/endpoint?filter[visible]=true` they could also request the endpoint without the filter.

I tried to create an token with this `get` variable set but I don’t think this works or is supposed to.

---

<div class="post-metadata">

**Author:** ![serjoscha87](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/serjoscha87/32/151_2.png) [@serjoscha87](https://discourse.getcockpit.com/u/serjoscha87)\
**Post date:** [April 9, 2020, 1:10pm UTC](https://discourse.getcockpit.com/t/solved-restrict-out-based-on-boolean/1339/4 "2020-04-09T13:10:13Z")

</div>

you could also create a custom route:

create a php file in: /config/api/\<your route name here\>.php

with content like this:

```
    return cockpit('collections')->find('collection_name', [
        'filter' => function($doc) { // make only visible entries being returned
            return $doc['visible'];
        }
    ]);

```

then you can call http://YOUR\_COCKPIT\_BACKEND\_URL/api/\<your route name here\>
