diff --git a/app/Traits/HasAttachments.php b/app/Traits/HasAttachments.php
index d39a144..040aa0b 100644
--- a/app/Traits/HasAttachments.php
+++ b/app/Traits/HasAttachments.php
@@ -28,7 +28,7 @@ trait HasAttachments
*/
public function getAttachments(): Collection
{
- return Cache::remember($this->cacheKey(), now()->addDays(28), function () {
+ return Cache::remember($this->attachmentsCacheKey(), now()->addDays(28), function () {
return $this->attachments()->get();
});
}
@@ -61,7 +61,7 @@ trait HasAttachments
}
}
- Cache::forget($this->cacheKey());
+ Cache::forget($this->attachmentsCacheKey());
$this->attachments()->createMany($attachmentItems);
}
@@ -72,7 +72,7 @@ trait HasAttachments
*/
public function deleteAttachments(): void
{
- Cache::forget($this->cacheKey());
+ Cache::forget($this->attachmentsCacheKey());
$this->morphMany(\App\Models\Attachment::class, 'addendum')->delete();
}
@@ -91,7 +91,7 @@ trait HasAttachments
*
* @return string
*/
- private function cacheKey(): string
+ private function attachmentsCacheKey(): string
{
return "attachments:{$this->getTable()}:{$this->id}";
}
diff --git a/app/Traits/HasGallery.php b/app/Traits/HasGallery.php
index 938bbea..4d074ce 100644
--- a/app/Traits/HasGallery.php
+++ b/app/Traits/HasGallery.php
@@ -50,6 +50,7 @@ trait HasGallery
}
}
+ Cache::forget($this->galleryCacheKey());
$this->gallery()->createMany($galleryItems);
}
@@ -65,13 +66,18 @@ trait HasGallery
public function getGallery(): Collection
{
- $cacheKey = 'gallery:' . $this->getTable() . ':' . $this->id;
- if (Cache::has($cacheKey) === true) {
- return Cache::get($cacheKey);
- }
+ return Cache::remember($this->galleryCacheKey(), now()->addDays(28), function () {
+ return $this->gallery()->get();
+ });
+ }
- $gallery = $this->morphMany(\App\Models\Gallery::class, 'addendum')->get();
- Cache::put($cacheKey, $gallery, now()->addDays(14));
- return $gallery;
+ /**
+ * Return the attachment cache key.
+ *
+ * @return string
+ */
+ private function galleryCacheKey(): string
+ {
+ return "gallery:{$this->getTable()}:{$this->id}";
}
}
diff --git a/resources/js/components/SMImageGallery.vue b/resources/js/components/SMImageGallery.vue
index 3c204fd..f027e0a 100644
--- a/resources/js/components/SMImageGallery.vue
+++ b/resources/js/components/SMImageGallery.vue
@@ -175,7 +175,7 @@ const handleAddToGallery = async () => {
if (result) {
const mediaResult = result as Media[];
let newValue = props.modelValue;
- let galleryIds = new Set(newValue.map((item) => item.id));
+ let galleryIds = new Set(mediaResult.map((item) => (item as Media).id));
mediaResult.forEach((item) => {
if (!galleryIds.has(item.id)) {
@@ -184,7 +184,7 @@ const handleAddToGallery = async () => {
}
});
- emits("update:modelValue", newValue);
+ emits("update:modelValue", mediaResult);
}
};
diff --git a/resources/js/components/dialogs/SMDialogMedia.vue b/resources/js/components/dialogs/SMDialogMedia.vue
index d60b6aa..05e0bf0 100644
--- a/resources/js/components/dialogs/SMDialogMedia.vue
+++ b/resources/js/components/dialogs/SMDialogMedia.vue
@@ -377,7 +377,7 @@
)}')`,
}">