Inheritance: extends AbstractValidator
Beispiel #1
0
 /**
  * @param CreateGroup $command
  * @return Group
  * @throws PermissionDeniedException
  */
 public function handle(CreateGroup $command)
 {
     $actor = $command->actor;
     $data = $command->data;
     $this->assertCan($actor, 'createGroup');
     $group = Group::build(array_get($data, 'attributes.nameSingular'), array_get($data, 'attributes.namePlural'), array_get($data, 'attributes.color'), array_get($data, 'attributes.icon'));
     $this->events->fire(new GroupWillBeSaved($group, $actor, $data));
     $this->validator->assertValid($group->getAttributes());
     $group->save();
     $this->dispatchEventsFor($group, $actor);
     return $group;
 }
Beispiel #2
0
 /**
  * @param EditGroup $command
  * @return Group
  * @throws PermissionDeniedException
  */
 public function handle(EditGroup $command)
 {
     $actor = $command->actor;
     $data = $command->data;
     $group = $this->groups->findOrFail($command->groupId, $actor);
     $this->assertCan($actor, 'edit', $group);
     $attributes = array_get($data, 'attributes', []);
     if (isset($attributes['nameSingular']) && isset($attributes['namePlural'])) {
         $group->rename($attributes['nameSingular'], $attributes['namePlural']);
     }
     if (isset($attributes['color'])) {
         $group->color = $attributes['color'];
     }
     if (isset($attributes['icon'])) {
         $group->icon = $attributes['icon'];
     }
     $this->events->fire(new GroupWillBeSaved($group, $actor, $data));
     $this->validator->assertValid($group->getDirty());
     $group->save();
     $this->dispatchEventsFor($group, $actor);
     return $group;
 }