Skip to content
This repository has been archived by the owner on Mar 18, 2022. It is now read-only.

Wildcard Permission and Roles #59

Closed
sniper7kills opened this issue Jun 16, 2015 · 4 comments
Closed

Wildcard Permission and Roles #59

sniper7kills opened this issue Jun 16, 2015 · 4 comments

Comments

@sniper7kills
Copy link
Contributor

While I believe this is due to the changes in laravel 5.1, I wanted to check here to see if anyone might have found a solution or work around.

I have the following roles:

admin
    level 999
admin.pages
    level 500
admin.users
    level 500

I used to do a check like this:

@role('root|admin|admin.*')

But now I'm unable to use wildcards in any of the checks. I'm assuming that laravel 5.1 removed the ability to use wildcards in a collection contains check and that is causing this.

@romanbican
Copy link
Owner

Well, I removed that functionality, because I thought it's unnecessary. I'll probably bring it back. Give me just a moment.

@romanbican
Copy link
Owner

Please, change method hasRole like this:

/**
 * Check if the user has role.
 *
 * @param int|string $role
 * @return bool
 */
protected function hasRole($role)
{
    return $this->getRoles()->contains(function ($key, $value) use ($role) {
        return $role == $value->id || str_is($role, $value->slug);
    });
}

And confirm if it's ok. I can't test it by myself right now. Thank you.

@sniper7kills
Copy link
Contributor Author

That does work.

Would you like me to make a PR with an updated hasRole as well as hasPermission?

@romanbican
Copy link
Owner

I'll do it. Thank you.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants