Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: add blade directives to check if user has certain role #12

Closed
lowerends opened this issue Oct 7, 2015 · 5 comments
Closed

Comments

@lowerends
Copy link
Contributor

It would be useful to have a blade directive that checks if a user has all or any of a given list (array) of roles. The syntax could be like this:

@has(['role_1', 'role_2', 'role_3'])
<some html/php here>
@else
<some other html/php here>
@endhas

What are your thoughts on this?

@freekmurze
Copy link
Member

I think it's a good idea to have that functionality, but I don't like the naming.

This would be better:

@role('administrator')
<some html/php here>
@endrole

@can does not have an else so I think @role shouldn't have else. @norole would be better.

Of course the directives should handle both strings and arrays.

If you would make a PR for this, I'd likely accept it.

@lowerends
Copy link
Contributor Author

I'm using @can with an @else part successfully. I think it will be important that you can define what needs to happen if the user doesn't have any or all of the roles.

As for the naming, it may be even better to make them consistent with the other PR I'm working on, to have @hasAnyRole and @hasAllRoles.

@freekmurze
Copy link
Member

In that case our blade directives should have an @else has well. Thanks for correcting me on this.

Good idea on the naming. Blade directives are generally lowercase so I prefer if the ones you add are lowercase as well. On top of the ones you're proposing a @role one (that has the behaviour of @hasanyrole) would be nice. @norole is still valuable so you aren't required to use an else.

Thoughts?

@lowerends
Copy link
Contributor Author

Agree, also with the fact that @norole can still be valuable.

So to sum up, we would have:

@role = @hasanyrole
@hasallroles
@else
@endrole, @endhasanyrole, @endhasallroles
@norole

@freekmurze
Copy link
Member

👍 go forth and code!

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

No branches or pull requests

2 participants