Fix import for new pivot table

This commit is contained in:
Annika Backstrom 2024-05-30 10:27:16 +01:00
parent aa820303ec
commit 10afc3836a
Signed by: annika
GPG Key ID: 3561F004DE1D9AFE

View File

@ -43,6 +43,7 @@ class ImportBookmark implements ShouldQueue
$bookmark->updated_at = $created_at; $bookmark->updated_at = $created_at;
$bookmark->save(); $bookmark->save();
$tags = [];
$tokens = explode(' ', $bookmark_json['tags']); $tokens = explode(' ', $bookmark_json['tags']);
foreach ($tokens as $tag_raw) { foreach ($tokens as $tag_raw) {
$tag = Tag::firstOrCreate( $tag = Tag::firstOrCreate(
@ -50,12 +51,10 @@ class ImportBookmark implements ShouldQueue
'name' => $tag_raw, 'name' => $tag_raw,
] ]
); );
$tags[$tag->id] = true;;
$bookmark_tag = new BookmarkTag;
$bookmark_tag->bookmark_id = $bookmark->id;
$bookmark_tag->tag_id = $tag->id;
$bookmark_tag->save();
} }
$bookmark->tags()->sync(array_keys($tags));
} }
} }
} }