Skip to content

can't use policies #978

@kandrejevs

Description

@kandrejevs

I have encountered problem where I have users with multiple roles and I want role1 to be able to manage users with role2 that belong to same model through belongsTo() relation.

I have written policy:

    public function view(User $user, User $model)
    {
        return true;
        if ($user->location->id === $model->location->id && $model->hasRole('role1')) {
            return true;
        }

        return false;
    }

when I use @can directive, policy works, but does not hit resolver due model: definition.

If I remove model from query, resolver is triggered, but policy fails due not passing 2nd argument, I get there only signed in user data.

last I tried to use $this->authorize('view', $user); within resolver, which throws error that authorize is undefined method.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions