Comments (7)
Is this what you want? https://github.com/romanbican/roles#entity-check
from roles.
I don't really understand where I must put the $user->attachPermission ? Is it on creating an article for example ?
from roles.
Well, you must have something like admin panel where you can attach roles and permissions.
from roles.
Okay, I made it work for articles.
But I still can't use it on the user profile.
I put this in my seeders :
And in my view I put :
$user being the user whose profile is displayed.
I tried logging in with an user, and whatever the profile I'm looking (my own or someone else's), the "test" is showing. I just want it to be displayed on my own profile page.
By the way, thank you for helping me, I'm not really at ease with Laravel for the moment.
from roles.
So, now I understand. I'll explain you.
If you want a user to edit all articles, give him permission edit.articles. Then he can edit all articles even if he didn't create them. If you don't give him permission, allowed() method will check if he created that article. But it is working only with belongsTo relationship.
If you want to check if the logged user can edit user he is looking at, you can make simple if statement like this:
@if(Auth::user()->id === $user->id)
//
@endif
There's no need to check for permissions unless you have a admin which can edit all users.
Hope it helps.
There is a allowed method, have a look:
/**
* Check if the user is allowed to manipulate with entity.
*
* @param string $providedPermission
* @param object $entity
* @param bool $owner
* @param string $ownerColumn
* @return bool
*/
public function allowed($providedPermission, $entity, $owner = true, $ownerColumn = 'user_id');
from roles.
As I have understood, permissions that attached to role doesn't provide entity check except such ones that attached directly to user. Am I right?
from roles.
No. They can be attached to role.
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.