bookmarks_json = $bookmarks_json; } /** * Execute the job. */ public function handle(): void { foreach ($this->bookmarks_json as $bookmark_json) { $created_at = DateTimeImmutable::createFromFormat(DateTimeInterface::ISO8601_EXPANDED, $bookmark_json['time']); $bookmark = new Bookmark; $bookmark->href = $bookmark_json['href']; $bookmark->title = $bookmark_json['description']; $bookmark->description = $bookmark_json['extended']; $bookmark->created_at = $created_at; $bookmark->updated_at = $created_at; $bookmark->save(); $tags = []; $tokens = explode(' ', $bookmark_json['tags']); foreach ($tokens as $tag_raw) { $tag = Tag::firstOrCreate( [ 'name' => $tag_raw, ] ); $tags[$tag->id] = true;; } $bookmark->tags()->sync(array_keys($tags)); } } }