Ejemplo n.º 1
0
 /**
  * @param $name
  * @return mixed
  */
 public function update($name)
 {
     if (Auth::user()->hasAccessTo('change', 'any', 'role')) {
         $role = Role::find($name);
         $allActions = Action::all();
         $allOwnerships = Ownership::all();
         $allEntities = Entity::all();
         if (Input::has('permissions')) {
             $role->permissions()->delete();
             foreach (Input::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->fill(Input::only(['name', 'description']));
         $role->save();
         return redirect()->route('roles.index');
     }
 }
Ejemplo n.º 2
0
 /**
  * @param $ownership
  * @throws InvalidOwnershipException
  */
 private function checkIfOwnershipExists($ownerships)
 {
     $allOwnerships = Ownership::all()->lists('name')->toArray();
     foreach ($ownerships as $ownership) {
         if (!in_array($ownership, $allOwnerships)) {
             $exception = new InvalidOwnershipException('The Ownership "' . $ownership . '" does not exist. Use one of: ' . implode(', ', $allOwnerships) . '.');
             $exception->ownership = $ownership;
             throw $exception;
         }
     }
 }