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

Blade templates #36

Closed
aronzillo opened this issue Jan 17, 2016 · 8 comments
Closed

Blade templates #36

aronzillo opened this issue Jan 17, 2016 · 8 comments

Comments

@aronzillo
Copy link

Do you have directives to use in blade templates? or it isn't necessary
For example:

@role('admin')
    <p>I'm an admin</p>
@endrole
@permission('create-user')
    <p>I can create users.</p>
@endpermission
@ability('admin,owner', 'create-user,edit-user')
    <p>Edit data</p>
@endability
@JosephSilber
Copy link
Owner

Bouncer works directly with Laravel's gate, so you can use the @can directive:

@can ('ability', $model)

I consider checking for roles directly an anti-pattern, so we don't ship an @is blade directive.

If you insist on checking directly for a role, you can use the standard @if directive:

@if ($user->is('admin'))

@aronzillo
Copy link
Author

Okay, you have reason. It is not neccesary repeat code. Thank you!

@Gummibeer
Copy link

If you want this you can do it your own with a BladeServiceProvider and add this blade tag.

But I also don't see any real reason to add this in the package.

@Gummibeer
Copy link

@JosephSilber
Copy link
Owner

To reiterate, I consider checking for roles directly something that shouldn't really ever be done.

To quote the docs:

Generally speaking, you should not have a need to check roles directly. It is better to allow a role certain abilities, then check for those abilities instead. If what you need is very general, you can create very broad abilities. For example, an access-dashboard ability is always better than checking for admin or editor roles directly.

Like I said above, if you still want to check for a user's role directly, you can use this:

@if ($user->is('admin'))
    // $user is an admin
@endif

@Arcesilas
Copy link
Contributor

For example, an access-dashboard ability is always better than checking for admin or editor roles directly

I think that this is precisely the reason why there is a @can blade directive and no @role by default in Laravel.

@JosephSilber
Copy link
Owner

@Arcesilas Laravel's own ACL has no notion of a role, so it wouldn't make sense for Laravel to ship a @role directive.

@Arcesilas
Copy link
Contributor

Ahem... You're right ^^ Sorry, tired nowadays...

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

No branches or pull requests

4 participants