/** * @param CreateLink $command * @return Link */ public function handle(CreateLink $command) { $actor = $command->actor; $data = $command->data; $this->assertAdmin($actor); $link = Link::build(array_get($data, 'attributes.title'), array_get($data, 'attributes.url'), array_get($data, 'attributes.isInternal'), array_get($data, 'attributes.isNewtab')); $this->validator->assertValid($link->getAttributes()); $link->save(); return $link; }
/** * @param EditLink $command * @return \Sijad\Links\Link * @throws \Flarum\Core\Exception\PermissionDeniedException */ public function handle(EditLink $command) { $actor = $command->actor; $data = $command->data; $link = $this->links->findOrFail($command->linkId, $actor); $this->assertAdmin($actor); $attributes = array_get($data, 'attributes', []); if (isset($attributes['title'])) { $link->title = $attributes['title']; } if (isset($attributes['url'])) { $link->url = $attributes['url']; } if (isset($attributes['isInternal'])) { $link->is_internal = $attributes['isInternal']; } if (isset($attributes['isNewtab'])) { $link->is_newtab = $attributes['isNewtab']; } $this->validator->assertValid($link->getDirty()); $link->save(); return $link; }