在 jwt / zizaco/entrust 中使用角色
Using roles with jwt / zizaco/entrust
在我的新 Laravel 5.8 应用程序中,我阅读了下一篇文章以使用具有 jwt 扩展的角色:
https://scotch.io/tutorials/role-based-authentication-in-laravel-with-jwt
在种子中我添加了几个角色,比如:
\DB::table('roles')->insert(array (
0 =>
array (
'id' => 1,
'name' => 'Admin',
'display_name' => 'Admin',
'description' => 'Administrator. Can do all operations in system',
'created_at' => '2019-04-29 11:03:50',
),
1 =>
array (
'id' => 2,
'name' => 'Manager',
'display_name' => 'Manager. Can do all operations in frontend and CRUD for Hostels/CMS items in Backend',
'description' => 'Manager description...',
'created_at' => '2019-04-29 11:03:50',
),
2 =>
array (
'id' => 3,
'name' => 'Customer',
'display_name' => 'Customer. Can do all operations in frontend',
'description' => 'Customer description...',
'created_at' => '2019-04-29 11:03:50',
),
));
当我需要为用户分配一些角色时,我看到了 assignRole 方法。
我不清楚权限和“permission_role”数据是什么。
我的简单应用程序结构需要它们吗?如果是,请提供一些例子...
谢谢!
如果您不指定您的应用程序需要做什么,我们将无法回答您的问题。根据您的应用程序,您可以拥有没有权限的角色或没有角色的权限。但是,如果您希望提供的教程有效,您需要它们。
权限是角色的特定操作。
示例权限 table 数据:
Permission-id: 1
Permission-name: 'Create Blog Post'
您可以将此权限分配给角色 'Admin' (Role-id: 1)。
您的 permission_role table 包含这两者之间的关系。所以对于上面的例子:
permission_role
'permission_id': 1, 'role_id': 1;
这意味着在这种情况下管理员角色可以 'Create Blog Post'。
在我的新 Laravel 5.8 应用程序中,我阅读了下一篇文章以使用具有 jwt 扩展的角色: https://scotch.io/tutorials/role-based-authentication-in-laravel-with-jwt 在种子中我添加了几个角色,比如:
\DB::table('roles')->insert(array (
0 =>
array (
'id' => 1,
'name' => 'Admin',
'display_name' => 'Admin',
'description' => 'Administrator. Can do all operations in system',
'created_at' => '2019-04-29 11:03:50',
),
1 =>
array (
'id' => 2,
'name' => 'Manager',
'display_name' => 'Manager. Can do all operations in frontend and CRUD for Hostels/CMS items in Backend',
'description' => 'Manager description...',
'created_at' => '2019-04-29 11:03:50',
),
2 =>
array (
'id' => 3,
'name' => 'Customer',
'display_name' => 'Customer. Can do all operations in frontend',
'description' => 'Customer description...',
'created_at' => '2019-04-29 11:03:50',
),
));
当我需要为用户分配一些角色时,我看到了 assignRole 方法。 我不清楚权限和“permission_role”数据是什么。 我的简单应用程序结构需要它们吗?如果是,请提供一些例子...
谢谢!
如果您不指定您的应用程序需要做什么,我们将无法回答您的问题。根据您的应用程序,您可以拥有没有权限的角色或没有角色的权限。但是,如果您希望提供的教程有效,您需要它们。
权限是角色的特定操作。
示例权限 table 数据:
Permission-id: 1
Permission-name: 'Create Blog Post'
您可以将此权限分配给角色 'Admin' (Role-id: 1)。
您的 permission_role table 包含这两者之间的关系。所以对于上面的例子:
permission_role
'permission_id': 1, 'role_id': 1;
这意味着在这种情况下管理员角色可以 'Create Blog Post'。