/** * @param $name * @return mixed */ public function update(UpdateRoleRequest $request, $name) { $role = Role::find($name); $role->fill($request->only(['name', 'description'])); if ($request->has('permissions')) { $allActions = Action::all(); $allOwnerships = Ownership::all(); $allEntities = Entity::all(); $role->permissions()->delete(); foreach ($request->get('permissions') as $entity => $actions) { foreach ($actions as $action => $ownership) { if ('no' !== $ownership) { $currentAction = $allActions->find($action); $currentOwnership = $allOwnerships->find($ownership); $currentEntity = $allEntities->find($entity); $currentPermission = new Permission(); $currentPermission->ownership()->associate($currentOwnership); $currentPermission->action()->associate($currentAction); $currentPermission->role()->associate($role); $currentPermission->entity()->associate($currentEntity); $currentPermission->save(); } } } } $role->save(); return redirect()->route('genealabs.laravel-governor.roles.index'); }