Closed RosiersRobin closed 8 years ago
@Advil-Robin Have you found a solution for your problem yet? If not i may be able to provide assistance. I am currently doing the same thing well actually i got the idea by your post (thanks for that), if i get it working ill share my code when and if i do get it working.
Hi @CallumCarmicheal !
Still didn't find the solution :(
Hope you can help me out!
@Advil-Robin I am currently doing a livestream on LiveCoding.TV, i am trying my method of doing this. Just to confirm you want a interactive (Disable/Enabled toggle) for each permission on a user / role right?
Link to stream: https://livecoding.tv/callumc
Yes so what I want is the ability to toggle permissions on or off on a role.
@Advil-Robin I've written a way to get the permissions in a role, so the only idea i can think of is to make another model and in that have the following methods, id, name, slug, description and inRole - bool. With that information you can get the perm with a id and the inRole property will tell you if the permission is in the role. Ill write the code for that now. Is that what you needed?
@Advil-Robin You want something like this right?
Euh I think so... if you look at the screen, that is what i like to make work.
@Advil-Robin Im uploading my code to github with a example. First im finding out what changes i have made to the source. Are you using Laravel 5.3?
@CallumCarmicheal I'm using Laravel 5.1, but I can modify the code more. I just need a sort of base.
@Advil-Robin Okay i have posted my solution on the repo, with a little example of flipping the roles. Every permission in the role is removed and every permission that is not in the role is added. So it flips the Enabled status. Take a look here. Hope this helps :)
Sidenote: i also added in a little sorting feature that can sort the slug or name. (it can be disabled if you read the params).
A example you could use for this is using the RolePermissions
to get and list of all the permissions and format them into the table, to get the permission $rp->permission->name
, and to enable/disable the permission you can use the object or when printing to the page store a hidden attribute on the button to toggle the row set it to the id of the permission and with that id you can attach the permission to the user. Thats how i am going to do it, maybe that makes sense or maybe not... But hope this helps XD
This is what i mean: Gif of my role permission manager
I've made something my own wich works really well.
With this I didn't need to change any code. I just checked if the permission exists in the database and if so, it's active, if not, then display as not active.
@Advil-Robin Hm, Im having the same issue. What did you do to check if the role has a specific permission? so confusing.
@jonjie0317 the tables are linked to each other, so you can just execute a query to check if the permission has a fole id.
@Advil-Robin what query you used?
@Advil-Robin I used <input type="checkbox" name="status" id="{{ $permission->slug }}"{{ ($permission->exists()) ? ' checked' : '' }}> {{ $permission->name }}
, and it returns all the permissions with all checked
@jonjie0317 What do you want to know, the permissions by the roles? Then I have this code:
@foreach($getperms as $perm)
<tr>
<td>{{ $perm->name }}</td>
<td>{{ $perm->description }}</td>
@if(!in_array($perm->id, $permbyrole))
<td><span id="{{ $perm->id }}" class="label label-danger">Not enabled</span></td>
<td><input onclick="toggleRole({{ $perm->id }}, {{ $role->id }})" type="checkbox" id="checkbox_{{ $perm->id }}"></td>
@else
<td><span id="{{ $perm->id }}" class="label label-success">Enabled</span></td>
<td><input onclick="toggleRole({{ $perm->id }}, {{ $role->id }})" type="checkbox" checked="true" id="checkbox_{{ $perm->id }}"></td>
@endif
</tr>
@endforeach
@Advil-Robin I got the idea on how to struct the table. hmm Just want to check all the permissions that the role has. For example, I want to list all the permissions, and if the id
of the role
passed in the uri have those permissions then, checked it using <input type="checkbox">
otherwise checkbox uncheck. Thanks a lot men
@Advil-Robin I need your help men :(
@jonjie0317 Make a question on [http://stackoverflow.com/](http://stackoverflow.com/, this is really not the place to help with such full questions. Post your link to it in a comment and I'll look at it.
@Advil-Robin here's the link sir http://stackoverflow.com/questions/43859917/how-to-get-list-of-permissions-in-a-role
test open
I'm currently trying to make this work:
http://image.prntscr.com/image/ac213fa5acc9477f912623f07f2f0576.png
Using this package to manage the roles.
However, this doesn't seem to work out for me. So I want to be able to manage the permissions by role. Like Role 'member' needs to have specific perms, but if necessary, I want to be able to add or remove those permissions. I really don't know how I should fix this and I'm stuck at the moment I need to show if the user has the permission enabled or not.
This is my current code:
HTML:
And this is my controller:
If someone could help me out with this, so I'm able to grant or revoke permissions and see if the permission is nabled or not would be awesome.