# Method 'App\\Policy\\UsersTablePolicy::beforeScope()' is not compatible with method

**URL:** <https://discourse.cakephp.org/t/method-app-policy-userstablepolicy-beforescope-is-not-compatible-with-method/12471>\
**Category:** Need Help\
**Tags:** help\
**Created:** [March 8, 2025, 8:21am UTC](https://discourse.cakephp.org/t/method-app-policy-userstablepolicy-beforescope-is-not-compatible-with-method/12471 "2025-03-08T08:21:44Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![lish](https://avatars.discourse-cdn.com/v4/letter/l/47e85d/32.png) [@lish](https://discourse.cakephp.org/u/lish)\
**Post date:** [March 8, 2025, 8:21am UTC](https://discourse.cakephp.org/t/method-app-policy-userstablepolicy-beforescope-is-not-compatible-with-method/12471/1 "2025-03-08T08:21:44Z")

</div>

**Fatal error** : Declaration of App\Policy\UsersTablePolicy::beforeScope(Authorization\IdentityInterface $user, Cake\Database\Query $query, string $action): Cake\Database\Query must be compatible with Authorization\Policy\BeforeScopeInterface::beforeScope(?Authorization\IdentityInterface $identity, mixed $resource, string $action): mixed in

 ![Screenshot From 2025-03-08 13-50-59](https://canada1.discourse-cdn.com/flex029/uploads/cakephp/original/2X/3/327ced6d70cc50804cdd018764b7a4d55a40652a.png)

---

<div class="post-metadata">

**Author:** ![jmcd73](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/jmcd73/32/481_2.png) [@jmcd73](https://discourse.cakephp.org/u/jmcd73)\
**Post date:** [March 9, 2025, 12:59am UTC](https://discourse.cakephp.org/t/method-app-policy-userstablepolicy-beforescope-is-not-compatible-with-method/12471/2 "2025-03-09T00:59:27Z")

</div>

Change your type hinting to match the BeforeScopeInterface in `vendor/cakephp/authorization/src/Policy/BeforeScopeInterface.php`

The interface definition:

```auto
public function beforeScope(?IdentityInterface $identity, mixed $resource, string $action): mixed;

```

i.e.

```auto
beforeScope(IdentityInterface $user, mixed $resource, string $action): mixed
{
     if ($user->getOriginalData()->is_trial_user) {
            return $query->where(['Articles.is_paid_only' => false]);
     }
}

```

---

<div class="post-metadata">

**Author:** ![dereuromark](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/dereuromark/32/37_2.png) [@dereuromark](https://discourse.cakephp.org/u/dereuromark)\
**Post date:** [March 9, 2025, 2:39am UTC](https://discourse.cakephp.org/t/method-app-policy-userstablepolicy-beforescope-is-not-compatible-with-method/12471/3 "2025-03-09T02:39:45Z")

</div>

> [@jmcd73](#):
>
> `mixed $resource`

`mixed $query`

is what you might want to use.

You can still annotate it as real query in the docblock above. This way you have autocomplete and PHPStorm also knows what this class is inside.

---

<div class="post-metadata">

**Author:** ![lish](https://avatars.discourse-cdn.com/v4/letter/l/47e85d/32.png) [@lish](https://discourse.cakephp.org/u/lish)\
**Post date:** [March 10, 2025, 6:07am UTC](https://discourse.cakephp.org/t/method-app-policy-userstablepolicy-beforescope-is-not-compatible-with-method/12471/4 "2025-03-10T06:07:36Z")

</div>

still it throw same error @jmcd73

---

<div class="post-metadata">

**Author:** ![lish](https://avatars.discourse-cdn.com/v4/letter/l/47e85d/32.png) [@lish](https://discourse.cakephp.org/u/lish)\
**Post date:** [March 10, 2025, 6:10am UTC](https://discourse.cakephp.org/t/method-app-policy-userstablepolicy-beforescope-is-not-compatible-with-method/12471/5 "2025-03-10T06:10:59Z")

</div>

how can resolve it @dereuromark and why cakephp does not provide this configure in out of the box… that why Laravel more popular framework because they provide pre-configuartions for login and role basse access system and easy to compatible with frontend Vue/Reactjs apps. please make cakephp next level in cakephp 6

---

<div class="post-metadata">

**Author:** ![Zuluru](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/zuluru/32/1230_2.png) [@Zuluru](https://discourse.cakephp.org/u/Zuluru)\
**Post date:** [March 10, 2025, 10:22pm UTC](https://discourse.cakephp.org/t/method-app-policy-userstablepolicy-beforescope-is-not-compatible-with-method/12471/6 "2025-03-10T22:22:47Z")

</div>

Your issues are PHP type errors, not CakePHP problems.

If you want an out-of-the-box login system, you might look at [GitHub - CakeDC/users: Users Plugin for CakePHP](https://github.com/CakeDC/users), and if you want role-based authentication, see [GitHub - CakeDC/auth: Auth objects for CakePHP](https://github.com/CakeDC/auth).

If you want to use Laravel, use Laravel. 🙂

---

<div class="post-metadata">

**Author:** ![dereuromark](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/dereuromark/32/37_2.png) [@dereuromark](https://discourse.cakephp.org/u/dereuromark)\
**Post date:** [March 11, 2025, 3:47pm UTC](https://discourse.cakephp.org/t/method-app-policy-userstablepolicy-beforescope-is-not-compatible-with-method/12471/7 "2025-03-11T15:47:32Z")

</div>

A more out of the box setup would also be possible with  
[GitHub - dereuromark/cakephp-tinyauth: CakePHP TinyAuth plugin for an easy and fast user authentication and authorization. Single or multi role. DB or config file based.](https://github.com/dereuromark/cakephp-tinyauth) together with the auth plugins.

---

<div class="post-metadata">

**Author:** ![shaan007](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/shaan007/32/2765_2.png) [@shaan007](https://discourse.cakephp.org/u/shaan007)\
**Post date:** [March 14, 2025, 3:45am UTC](https://discourse.cakephp.org/t/method-app-policy-userstablepolicy-beforescope-is-not-compatible-with-method/12471/8 "2025-03-14T03:45:57Z")

</div>

I think, this code may help or resolve your problem @lish . May be Cakephp Authorization Documents not updated therefore this confusion… but this code definitely work

```auto
public function beforeScope(?IdentityInterface $identity, mixed $resource, string $action): mixed
    {
        // Assuming $resource is the query you want to modify, and $identity is the user
        if ($identity->getOriginalData()->is_trial_user) {
            return $resource;
        }

        // fall through
        return null;
    }

```
