Comments (8)
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.
Okay, you have reason. It is not neccesary repeat code. Thank you!
from bouncer.
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.
https://laravel.com/docs/5.2/blade#extending-blade
from bouncer.
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 foradmin
oreditor
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.
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.
@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.
Ahem... You're right ^^ Sorry, tired nowadays...
from bouncer.
Related Issues (20)
- Frontend - Check if user can own a model HOT 1
- Ability Options Bouncer::can not return abilities or mistake HOT 1
- Ability Cast Blocks UUID on 'entity_id' HOT 2
- Bouncer::role() return empty array HOT 2
- User::roles() returns empty collection when scope is null HOT 12
- Get Direct Abilities - Not via Roles HOT 2
- setup with filament not working HOT 1
- No migrations when upgrading from 1.0.0-rc.3 HOT 1
- Question: How can I get certain model Instance's users with ability 'update' ? HOT 1
- Can helper returning true after removing role from the user HOT 2
- error foreign keys with Planetscale HOT 3
- How To Add / Remove Roles Temporarily (for current request only) ? HOT 5
- [HELP] Extend Ability HOT 1
- Migration issues using Multitenancy System HOT 8
- Get all users with all their roles HOT 2
- scope is not reset between tests HOT 3
- Fine grade check delete ability
- Adjust connection for can() gate
- How to get owns and check is owned
- Is it possible to keep all abilities hardcoded instead of abilities table HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bouncer.