diff --git a/app/Http/Controllers/PhotoItemTagsController.php b/app/Http/Controllers/PhotoItemTagsController.php index d5bd6c6f..aabd2c07 100644 --- a/app/Http/Controllers/PhotoItemTagsController.php +++ b/app/Http/Controllers/PhotoItemTagsController.php @@ -15,7 +15,7 @@ public function store(PhotoItem $photoItem, StorePhotoItemTagRequest $request): abort(404); } - $photoItem->tags()->syncWithoutDetaching($request->input('tag_id')); + $photoItem->tags()->syncWithoutDetaching($request->input('tag_ids')); return response()->json(); } diff --git a/app/Http/Requests/StorePhotoItemTagRequest.php b/app/Http/Requests/StorePhotoItemTagRequest.php index ecefe9e1..429ad97e 100644 --- a/app/Http/Requests/StorePhotoItemTagRequest.php +++ b/app/Http/Requests/StorePhotoItemTagRequest.php @@ -15,7 +15,8 @@ class StorePhotoItemTagRequest extends FormRequest public function rules(): array { return [ - 'tag_id' => 'required|exists:tags,id', + 'tag_ids' => 'required|array', + 'tag_ids.*' => 'required|integer|exists:tags,id', ]; } } diff --git a/resources/js/Components/TagBox.vue b/resources/js/Components/TagBox.vue index 825b5c08..e0a5e701 100644 --- a/resources/js/Components/TagBox.vue +++ b/resources/js/Components/TagBox.vue @@ -17,9 +17,13 @@ const props = defineProps({ type: Boolean, default: false, }, - dropdownWidth: { + nullable: { + type: Boolean, + default: false, + }, + placeholder: { type: String, - default: 'w-full md:w-96 right-0', + default: '', }, }); @@ -59,6 +63,7 @@ onMounted(() => { :modelValue="modelValue" @update:modelValue="value => $emit('update:modelValue', value)" :multiple="multiple" + :nullable="nullable" by="id" >
@@ -67,6 +72,7 @@ onMounted(() => { ref="input" class="w-full rounded-md border-0 bg-white dark:bg-gray-900 py-1.5 pl-3 pr-12 text-gray-900 dark:text-gray-300 shadow-sm ring-1 ring-inset ring-gray-300 dark:ring-gray-700 focus:ring-2 focus:ring-inset focus:ring-indigo-500 dark:focus:ring-indigo-600 sm:text-sm sm:leading-6" :displayValue="(item) => item?.name" + :placeholder="placeholder" @change="query = $event.target.value" @focus="$event.target.select()" autocomplete="off" @@ -96,8 +102,7 @@ onMounted(() => { @after-leave="query = ''" >
{ + return [ + selectedMaterialTag.value?.id, + selectedBrandTag.value?.id, + selectedEventTag.value?.id, + selectedStateTag.value?.id, + selectedContentTag.value?.id, + selectedSizeTag.value?.id, + ].filter(tag => tag); +}); const tagNames = computed(() => { return item.value.tag_ids.map(function (tagId) { @@ -32,13 +43,17 @@ const tagNames = computed(() => { }); }); -const addTagToItem = (tag) => { - if (item.value.tag_ids.find(itemTag => itemTag === tag.id)) { - return; - } +const addTagsToItem = () => { + item.value.tag_ids = [...new Set([...item.value.tag_ids, ...selectedTagIds.value])]; - item.value.tag_ids.push(tag.id); emit('change', item.value); + + selectedMaterialTag.value = null; + selectedBrandTag.value = null; + selectedEventTag.value = null; + selectedStateTag.value = null; + selectedContentTag.value = null; + selectedSizeTag.value = null; }; const removeTagFromItem = (tagId) => { @@ -75,110 +90,63 @@ const copyItem = () => {
-
-
- - - - Add Material - -
- -
- - - - Add Brand - -
- -
- - - - Add Content - -
- -
- - - - Add Size - -
- -
- - - - Add State - -
- -
- - - - Add Event - -
+
+ + + + + + + + + + + +
-
+
{ aria-hidden="true"> {{ tag.name }} -
+
+ +
+ + Add Selected Tags +
diff --git a/resources/js/Pages/Photos/Partials/PhotoItem.vue b/resources/js/Pages/Photos/Partials/PhotoItem.vue index c7859395..dfae199a 100644 --- a/resources/js/Pages/Photos/Partials/PhotoItem.vue +++ b/resources/js/Pages/Photos/Partials/PhotoItem.vue @@ -1,5 +1,5 @@