Skip to content

How to skip the model_has_permissions query when no directly assigned permissions are present? #2351

Closed Answered by anwarx4u
anwarx4u asked this question in Q&A
Discussion options

You must be logged in to vote

I have successfully overridden the HasPermissions trait in the user model using the following code, and it is currently functioning as intended. However, I would like to know if there is a better way to achieve this.

public function getAllPermissions(): Collection
    {
  
       $permissions = $this->permissions; // replaced by below line
        $permissions = collect();
       if (method_exists($this, 'roles')) {
            $permissions = $permissions->merge($this->getPermissionsViaRoles());
        }

        return $permissions->sort()->values();
    }

    public function hasDirectPermission($permission): bool
    {
        return false;
    }

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@drbyte
Comment options

@emmanuelsoto22
Comment options

@drbyte
Comment options

Answer selected by drbyte
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants