Laravel-permission: [Request] Add a "key" column, separate from display-name

Created on 26 Feb 2018  Â·  7Comments  Â·  Source: spatie/laravel-permission

Hi. Please, roles and permission name exists, and  add new row to db for roles and permission name key. name and key stored different rows. new db structure is 
Roles table
ID     Name     Role          Guard name
1       Admin    admin       web
--------------------------------------------
ID     Name            Role                Guard name
2       Moderator    moderator       web

Permissions table
ID     Name                   Permission             Guard name
1       Read message    read-message       web
-------------------------------------------------------------
ID     Name                   Permission             Guard name
2       Delete message    delete-messages      web
revisit for future version

Most helpful comment

I agree it would be really useful for permissions to have some more human readable attributes in addition to the "key" used to do the actual permission checks. To maintain backwards compatability, name would still be used as the "key" to check against, but each permissions could also store an optional displayname and description.

As to the why, we'd be able to make a much better front-end experience for assigning/revoking roles and permissions if we had some more information stored for each one...

[ ] {{ permission.displayname }} - Allow {{ user.name }} to {{ permission.description }}.
[ ✓ ] Edit Users - Allow Jane to add, update and delete users?
[ ✓ ] Edit Other's Posts - Allow Jane to edit and trash other user's posts?

We can obviously just make the existing name field more readable for administration purposes, but imo it also doesn't feel right to be doing my checks against a key string containing capitalisation/spaces, although that could just be a personal preference of mine.

All of the above applies for Roles too.

All 7 comments

Please explain "why" you are requesting this.

Because it seems to be inconsistent.
When the role name is "admin", it will be better to appear on the site as "Admin".

I agree it would be really useful for permissions to have some more human readable attributes in addition to the "key" used to do the actual permission checks. To maintain backwards compatability, name would still be used as the "key" to check against, but each permissions could also store an optional displayname and description.

As to the why, we'd be able to make a much better front-end experience for assigning/revoking roles and permissions if we had some more information stored for each one...

[ ] {{ permission.displayname }} - Allow {{ user.name }} to {{ permission.description }}.
[ ✓ ] Edit Users - Allow Jane to add, update and delete users?
[ ✓ ] Edit Other's Posts - Allow Jane to edit and trash other user's posts?

We can obviously just make the existing name field more readable for administration purposes, but imo it also doesn't feel right to be doing my checks against a key string containing capitalisation/spaces, although that could just be a personal preference of mine.

All of the above applies for Roles too.

I also think a key column is needed.
My apps are in french so the roles must be displayed in french, wich leads to awfull php code:
$user->hasRole('Administrateur')

You also could use the name attribute as a key to translate in your views like this example :

    @lang('roles.name.' . $role->name)

This way, your role name would be well translated for all your app languages.
But I agree that a key attribute would have been more comprehensive than a name field.
And in the other hand, the role translated role name would not been editable in a backoffice.

Maybe using one of the following packages could do the trick :

Yeah but that mean you could'nt create new role on your admin panel for exemple

For maximum flexibility with multilanguage applications, using the name field as the "key" and using language-translation of it (everywhere you want to display it) generally works best.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ionesculiviucristian picture ionesculiviucristian  Â·  4Comments

hosseinnedaei picture hosseinnedaei  Â·  3Comments

ghost picture ghost  Â·  3Comments

neoreids picture neoreids  Â·  3Comments

bbdangar picture bbdangar  Â·  4Comments