Exemplo n.º 1
0
 protected function create($values)
 {
     $data = [];
     foreach ($this->structure as $i => $key) {
         $data[$key] = $values[$i];
     }
     PermissionUser::create($data);
 }
 public function lastUpdated()
 {
     $query = PermissionUser::orderBy('updated_at', 'DESC')->first();
     if ($query) {
         return $query->updated_at->format('Y-m-d H:i:s');
     }
     return date("Y-m-d H:i:s");
 }
 /**
  * @param int $userID
  * @param array $groupIDs
  */
 public function updateUserGroupPermissions($userID, array $groupIDs)
 {
     $permissionUser = $this->createModel()->getPermissionActions($userID)->pluck('permission_action_id', 'permission_id');
     $permissionGroup = $this->createModel()->getPermissionActions($groupIDs, null, 'group')->pluck('permission_action_id', 'permission_id')->unique();
     //We add permissions that the group has but the user doesn't.
     $permissionsToAdd = $permissionGroup->diff($permissionUser);
     if (!$permissionsToAdd->isEmpty()) {
         foreach ($permissionsToAdd as $actionID) {
             $this->addUserPermission($userID, $actionID);
         }
     }
     //We remove permissions the user has that the group doesn't.
     $permissionsToRemove = $permissionUser->diff($permissionGroup);
     if (!$permissionsToRemove->isEmpty()) {
         PermissionUser::deletePermissionUsers($permissionsToRemove->keys()->toArray());
     }
 }