Coder Social home page Coder Social logo

Blade templates about bouncer HOT 8 CLOSED

josephsilber avatar josephsilber commented on May 20, 2024
Blade templates

from bouncer.

Comments (8)

JosephSilber avatar JosephSilber commented on May 20, 2024

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'))

from bouncer.

aronzillo avatar aronzillo commented on May 20, 2024

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

from bouncer.

Gummibeer avatar Gummibeer commented on May 20, 2024

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.

from bouncer.

Gummibeer avatar Gummibeer commented on May 20, 2024

https://laravel.com/docs/5.2/blade#extending-blade

from bouncer.

JosephSilber avatar JosephSilber commented on May 20, 2024

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

from bouncer.

Arcesilas avatar Arcesilas commented on May 20, 2024

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.

from bouncer.

JosephSilber avatar JosephSilber commented on May 20, 2024

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

from bouncer.

Arcesilas avatar Arcesilas commented on May 20, 2024

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

from bouncer.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.