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
Change your type hinting to match the BeforeScopeInterface in vendor/cakephp/authorization/src/Policy/BeforeScopeInterface.php
The interface definition:
public function beforeScope(?IdentityInterface $identity, mixed $resource, string $action): mixed;
i.e.
beforeScope(IdentityInterface $user, mixed $resource, string $action): mixed
{
if ($user->getOriginalData()->is_trial_user) {
return $query->where(['Articles.is_paid_only' => false]);
}
}
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.
still it throw same error @jmcd73
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
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, and if you want role-based authentication, see GitHub - CakeDC/auth: Auth objects for CakePHP.
If you want to use Laravel, use Laravel.
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. together with the auth plugins.
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
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;
}