我正在尝试将角色(或权限)设置为Laravel背包(newscrud)中的类别。 我在DB的CategoryCrudController类和category_role表中添加了Role字段,并在Category和Role模型中设置了关系。 关系数据现在存储在表中,尽管未选中该复选框!
$this->crud->addField(
[
'label' => 'Roles',
'type' => 'checklist',
'name' => 'roles',
'entity' => 'roles',
'attribute' => 'name',
'model' => "Backpack\PermissionManager\app\Models\Role",
'pivot' => true,
]
);
现在,我想允许具有授予角色的用户在类别的文章上使用crud。 我知道我可以在CrudController的设置函数中使用hasRole并使用denyAccess(),但这不是我想要的。
public function setup(){
if (backpack_user()->hasRole('certainCategoryRole')) {
$this->crud->denyAccess([ 'delete','edit','write']);
}
}
我需要按类别的分配角色为用户提供商品操作访问权限。
有人可以帮忙吗?
感谢