我计划在laravel 5.3中实现sentinel的权限。我在配置文件夹中创建了permissions.php
。
config / permissions.php文件
<?php
return array(
'User Management -> Role Management' => array(
array(
'permission' => 'role-management.view',
'label' => 'View',
),
array(
'permission' => 'role-management.create',
'label' => 'Create',
),
array(
'permission' => 'role-management.edit',
'label' => 'Edit',
),
array(
'permission' => 'role-management.delete',
'label' => 'Delete',
),
),
'User Management -> User Management' => array(
array(
'permission' => 'user-management.view',
'label' => 'View',
),
array(
'permission' => 'user-management.create',
'label' => 'Create',
),
array(
'permission' => 'user-management.edit',
'label' => 'Edit',
),
array(
'permission' => 'user-management.delete',
'label' => 'Delete',
),
),
);
然后,在我的控制器中,我创建了一个查看的获取路径。
路线
Route::get('/manage-role/edit/{slug}', ['as' => 'edit', 'uses' => 'RoleController@edit']);
我的控制器方法如下所示
public function edit($slug)
{
//get selected role ex: admin, manager or user
$role = Sentinel::findRoleBySlug($slug);
$permissions = Config::get('permissions');
foreach ($permissions as $permission) {
foreach ($permission as $eachPermission) {
$encodedPermission = base64_encode($eachPermission['permission']);
$eachPermission['encodedPermission'] = $encodedPermission;
}
}
//return view
return view('backend.admin.user-management.edit-role', [
'role' => $role,
'permissions' => $permissions
]);
}
我的观点看起来像这样,我已经删除了引导程序,而其他只是专注于逻辑。
修改-role.blade.php
<form action="" method="post">
@foreach ($permissions as $permissionHeader => $permissions)
<h3 class="box-title">{{ $permissionHeader }}</h3>
@foreach ($permissions as $key => $permission)
<label class="control-group">{{{ $permission['label'] }}}</label>
<input type="radio" name="{{ $permission['label'] }}" class="flat-red" checked> Enable
<input type="radio" name="{{ $permission['label'] }}" class="flat-red"> Disable
</label>
@endforeach
@endforeach
<button type="submit" class="btnRoleForm btn btn-success">Save Roles</button>
</div>
</form>
这是从管理员仪表板
设置管理员权限的图像我想检查每个权限的单选按钮创建,查看,更新,删除每种类型(用户管理,角色管理等)。我现在被困了。
当我在刀片中使用name="{{ $permission['encodedPermission'] }}"
时,我收到错误消息。此键未在数组中设置。
我想在保存按钮上设置所有权限。我做得正确还是有其他有效的方法来做到这一点。求助。