Comments (5)
Hi,
you always need to have User object. If we're talking only about Blade, you can take advantage of view composers in Laravel 5.
Then you can have something like this:
@if ($currentUser->is('admin'))
//
@endif
Instead of this:
@if (Auth::user()->is('admin'))
// something
@endif
But if I understand correctly, you want something like this?
@role ('admin')
// something
@endrole
@permission ('edit_articles')
// something
@endpermission
Please, specify me your vision :-).
from roles.
There is also a very nice video about view composers in Laravel 5. Have a look!
from roles.
This solution would be amazing:
@role ('admin')
// something
@endrole
The below made me perfectly happy:
@if (Auth::user()->is('admin'))
// something
@endif
What I was unable to do in my L4 solution was using multiple conditions. I just used ||
Can you give me an example of a syntax for sth like this:
@if (Auth::user()->is('admin') || Auth::user()->is('Developer'))
desired solution would be sth like this:
@if (Auth::user()->is('Admin','Developer')
Generally I would add more complicated examples in the readme.md file.
After you answer I will prepare a pull request with all working examples you have provided. My pleasure.
from roles.
There is a way to check for multiple roles or permissions in one condition in my package.
if ($user->is('admin|moderator')) // or $user->is('admin, moderator') or $user->is(['admin', 'moderator'])
{
// if user has at least one role
}
if ($user->is('admin|moderator', 'all')) // or $user->is('admin, moderator', 'all') or $user->is(['admin', 'moderator'], 'all')
{
// if user has all roles that we check for
}
The same syntax applies to permissions.
Later today, I'll be working on this syntax for Blade:
@role ('admin')
// something
@endrole
from roles.
New release is out. Check it out. There are some changes.
from roles.
Related Issues (20)
- how to use middleware in controller with 'or' condition
- Unique property on field slug in the roles table
- can() method judge super admin role has all permission by default
- managing permissions by role HOT 22
- About 1050 Table 'role_user' already exists
- Migrations broken in 5.3
- Declaration of Illuminate\Database\Eloquent\Model::is HOT 2
- user model issue using laravel 5.3 HOT 3
- How to get all roles without User
- Replace foreign keys
- Rollbac migration error Laravel 5.2 HOT 1
- User.php error HOT 1
- Class 'App\Model' not found HOT 1
- How I can get all users which have Role admin
- hasPermission inside VerifyPermission is not working properly HOT 3
- Is there support AND/OR operatos in the middleware?
- Is this project maintained any more? HOT 2
- This Project is DEAD. HOT 2
- Error (1/1) FatalErrorException Interface
- hasRole and permission works with $key not $value 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 roles.