PHPackages                             doefom/restrict - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Admin Panels](/categories/admin)
4. /
5. doefom/restrict

ActiveLibrary[Admin Panels](/categories/admin)

doefom/restrict
===============

A Statamic addon that applies your EntryPolicy's `view` method to entry listings in the control panel.

v0.5.4(2y ago)32.4k1MITPHP

Since Mar 7Pushed 2y ago1 watchersCompare

[ Source](https://github.com/doefom/restrict)[ Packagist](https://packagist.org/packages/doefom/restrict)[ RSS](/packages/doefom-restrict/feed)WikiDiscussions main Synced 2d ago

READMEChangelog (10)Dependencies (1)Versions (17)Used By (0)

Restrict
========

[](#restrict)

> A Statamic addon that applies your EntryPolicy's `view` method to entry listings in the control panel.

- ✅ Statamic v4
- ✅ Statamic v5
- ✅ Multisite
- ❌ Eloquent Driver

**Note:** Statamic Pro is required.

Features
--------

[](#features)

Prevent entries from showing up in the control panel based on the `EntryPolicy` you define.

Upgrade Guide
-------------

[](#upgrade-guide)

### From 0.4.x to 0.5.x

[](#from-04x-to-05x)

In versions v0.4.x you had to set a restriction closure in the `AppServiceProvider` to restrict entries. This will no longer work. Instead, you can now set the restriction by extending the `Statamic\Policies\EntryPolicy` class and adjust the `view` method to your needs, since this policy method will now be respected when querying entries in the control panel.

Before, you've set your restrictions like this:

```
// v0.4.x:

use Doefom\Restrict\Facades\Restrict;
use Statamic\Contracts\Auth\User;
use Statamic\Contracts\Entries\Entry;

class AppServiceProvider extends ServiceProvider
{
    public function register(): void
    {
        // ...
    }

    public function boot(): void
    {
        Restrict::setRestriction(function (User $user, Entry $entry) {
            // Can view own entries only
            return $entry->authors()->contains($user->id());
        });
    }
}
```

Now you have to set your restrictions as explained in the [Getting Started](#getting-started) section.

### From 0.3.x to 0.4.x

[](#from-03x-to-04x)

In versions up to 0.3.x there were hard coded permissions to `view other authors' entries` on a per-collection basis. Those permissions are now removed and will no longer have any effect by default.

Getting Started
---------------

[](#getting-started)

### Installation

[](#installation)

You can search for this addon in the `Tools > Addons` section of the Statamic control panel and click **install**, or run the following command from your project root:

```
composer require doefom/restrict
```

### Create a Custom Entry Policy

[](#create-a-custom-entry-policy)

To properly use this addon it's best to create a custom entry policy. **Make sure it extends the default** `Statamic\Policies\EntryPolicy` and overrides its `view` method. This method will be called to determine if an entry is listed in the control panel or not.

**Tip:** You can create a custom policy by running:

```
php artisan make:policy MyEntryPolicy
```

Here is what `MyEntryPolicy` could look like:

```
