/** * @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 DeleteTag $command * @return \Flarum\Tags\Tag * @throws \Flarum\Core\Exception\PermissionDeniedException */ public function handle(DeleteTag $command) { $actor = $command->actor; $tag = $this->tags->findOrFail($command->tagId, $actor); $this->assertCan($actor, 'delete', $tag); $tag->delete(); return $tag; }
/** * @param DeleteTag $command * @return \Flarum\Tags\Tag * @throws \Flarum\Core\Exception\PermissionDeniedException */ public function handle(DeleteTag $command) { $actor = $command->actor; $tag = $this->tags->findOrFail($command->tagId, $actor); $this->assertCan($actor, 'delete', $tag); $this->tags->query()->where('parent_id', $tag->id)->update(['parent_id' => null]); $tag->delete(); return $tag; }