Exemplo n.º 1
0
 /**
  * @param DeleteLink $command
  * @return \Sijad\Links\Link
  * @throws \Flarum\Core\Exception\PermissionDeniedException
  */
 public function handle(DeleteLink $command)
 {
     $actor = $command->actor;
     $link = $this->links->findOrFail($command->linkId, $actor);
     $this->assertAdmin($actor);
     $link->delete();
     return $link;
 }
Exemplo n.º 2
0
 /**
  * @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;
 }