diff --git a/resources/js/views/dashboard/PostEdit.vue b/resources/js/views/dashboard/PostEdit.vue
index e4c2005..85a2f3c 100644
--- a/resources/js/views/dashboard/PostEdit.vue
+++ b/resources/js/views/dashboard/PostEdit.vue
@@ -49,7 +49,7 @@
-
+
@@ -170,6 +170,13 @@ const loadData = async () => {
: "";
form.controls.content.value = data.post.content;
form.controls.hero.value = data.post.hero;
+
+ attachments.value = (data.post.attachments || []).map(function (
+ attachment
+ ) {
+ return attachment.id.toString();
+ });
+ console.log(attachments.value);
} else {
pageError.value = 404;
}
@@ -195,18 +202,33 @@ const handleSubmit = async () => {
hero: form.controls.hero.value,
};
+ let post_id = "";
+
if (route.params.id) {
+ post_id = route.params.id as string;
await api.put({
url: `/posts/${route.params.id}`,
body: data,
});
} else {
- await api.post({
+ let result = await api.post({
url: "/posts",
body: data,
});
+
+ if (result.data) {
+ const data = result.data as PostResponse;
+ post_id = data.post.id;
+ }
}
+ await api.put({
+ url: `/posts/${post_id}/attachments`,
+ body: {
+ attachments: attachments.value,
+ },
+ });
+
useToastStore().addToast({
title: route.params.id ? "Post Updated" : "Post Created",
content: route.params.id