/** * @param EditTag $command * @return \Flarum\Tags\Tag * @throws \Flarum\Core\Exception\PermissionDeniedException */ public function handle(EditTag $command) { $actor = $command->actor; $data = $command->data; $tag = $this->tags->findOrFail($command->tagId, $actor); $this->assertCan($actor, 'edit', $tag); $attributes = array_get($data, 'attributes', []); if (isset($attributes['name'])) { $tag->name = $attributes['name']; } if (isset($attributes['slug'])) { $tag->slug = $attributes['slug']; } if (isset($attributes['description'])) { $tag->description = $attributes['description']; } if (isset($attributes['color'])) { $tag->color = $attributes['color']; } if (isset($attributes['isHidden'])) { $tag->is_hidden = (bool) $attributes['isHidden']; } if (isset($attributes['isRestricted'])) { $tag->is_restricted = (bool) $attributes['isRestricted']; } event(new TagWillBeSaved($tag, $actor, $data)); $this->validator->assertValid($tag->getDirty()); $tag->save(); return $tag; }
/** * @param CreateTag $command * @return Tag */ public function handle(CreateTag $command) { $actor = $command->actor; $data = $command->data; $this->assertCan($actor, 'createTag'); $tag = Tag::build(array_get($data, 'attributes.name'), array_get($data, 'attributes.slug'), array_get($data, 'attributes.description'), array_get($data, 'attributes.color'), array_get($data, 'attributes.isHidden')); $this->validator->assertValid($tag->getAttributes()); $tag->save(); return $tag; }