firstOrFail(); if (Arr::get($data, 'update_replace')) { foreach (Arr::get($data, 'update_replace') as $property => $value) { if ($property === 'content') { $note->note = $value[0]; } if ($property === 'syndication') { $this->applySyndication($note, $value); } } $note->save(); return [ 'response' => 'updated', 'url' => $note->uri, ]; } if (Arr::get($data, 'update_add')) { foreach (Arr::get($data, 'update_add') as $property => $value) { if ($property === 'syndication') { $this->applySyndication($note, $value); } if ($property === 'photo') { foreach ($value as $photoURL) { if (Str::startsWith($photoURL, 'https://')) { $media = new Media; $media->path = $photoURL; $media->type = 'image'; $media->save(); $note->media()->save($media); } } } } $note->save(); return [ 'response' => 'updated', 'url' => $note->uri, ]; } throw new MicropubHandlerException('Unsupported update operation'); } private function applySyndication(Note $note, array $urls): void { foreach ($urls as $url) { if (Str::startsWith($url, 'https://www.facebook.com')) { $note->facebook_url = $url; } elseif (Str::startsWith($url, 'https://www.swarmapp.com')) { $note->swarm_url = $url; } elseif (Str::startsWith($url, 'https://twitter.com')) { $note->tweet_id = basename(parse_url($url, PHP_URL_PATH)); } } } }