向一个角色添加多个权限委托Laravel 5的基于角色的权限
I just add entrust to Laravel project, i can create role, create permission , attachPermission, assignRole.
Now i want to attach multiple permissions to one Role ,for example i add this permissions [create-user,edit-user,remove-user,update-user] to superAdmin Role.
public function attachPermission(Request $request){
$role = Role::where('name', '=', $request->input('role'))->first();
$permission = Permission::where('name', '=', $request->input('name'))->first();
foreach ($permission as $pers){
$role->attachPermissions($pers);
}
return response()->json("done");
}
This code take last just permission, this is a backend i test with Postman.
So what's the best why to do it ? and thanks for help .
dtm37893
2016/09/08 10:20- laravel
- permissions
- json
- php
- 点赞
- 收藏
- 回答
满意答案
1个回复
