首页 > 解决方案 > Laravel spatie/laravel-permissions Naming Conventions

问题描述

Are there some naming guidelines I should be following when it comes to naming permissions? Right now, everything I find is just along the lines of "Add Foo","Edit Foo","Delete Foo","Add FooBar","Edit FooBar","Delete FooBar", and so forth and so forth.

Keeping in mind that there is no grouping (which is a real pity), and when you have a management screen for all said permissions - the above approach seems quite sloppy.

All your "adds" are together, "edits" are together, etc. eg:

 - Add Foo
 - Add FooBar
 - Add FooBarBez
 - Edit Foo
 - Edit FooBar
 - Edit FooBarBez
 - Delete Foo
 - Delete FooBar
 - Delete FooBarBez

Right now I'm leaning towards something along the lines of what route names look like, for example:

 - foo.add
 - foo.edit
 - foo.delete
 - foobar.add
 - foobar.edit
 - foobar.delete
 - foobarbez.add
 - foobarbez.edit
 - foobarbez.delete

It's more organised in terms of keeping all the 'parent' permissions together (ie: all Foo's together, all FooBar's together, etc). Of course, if there are actual guidelines for this, please do let me know or if you have other valuable input / suggestions?

//Edit Update for Clarity

Specifically,

- __Are__ any naming conventions? 
- Are there any preferences in terms of use of singular/plural when it comes to parents (eg: "User Create", "Users Create")
- If parents and action should be separated with a space, a dot, something else? (eg: "users.create"; "users create"; "users->create")
- What about nested resources (Parent.Child)? eg: "users.banking_details.create"
- Captilisation? Lowercase? Camel Case?

As mentioned previously, leaning towards laravel named routes as the guideline so would be: plural, lowercase, separated by dots, including full path (parent+child relationship). Just because thats what I'm leaning towards, doesnt mean its right though, hence me asking for input from the community :)

标签: laravellaravel-5naming-conventionsuser-permissionslaravel-permission

解决方案


我会使用Laravel 在授权资源时使用的相同名称

  • view
  • create
  • update
  • delete

你可以在这里阅读更多相关信息:Laravel 中的门和授权改进


推荐阅读