diff --git a/app/Http/Requests/Document/Document.php b/app/Http/Requests/Document/Document.php index 9d7a9ebbd..fc1da618d 100644 --- a/app/Http/Requests/Document/Document.php +++ b/app/Http/Requests/Document/Document.php @@ -61,7 +61,7 @@ class Document extends FormRequest 'contact_id' => 'required|integer', 'contact_name' => 'required|string', 'category_id' => 'required|integer', - 'attachment' => $attachment, + 'attachment.*' => $attachment, ]; } diff --git a/app/Jobs/Document/CreateDocument.php b/app/Jobs/Document/CreateDocument.php index 9efa67ca1..6db91209d 100644 --- a/app/Jobs/Document/CreateDocument.php +++ b/app/Jobs/Document/CreateDocument.php @@ -43,9 +43,11 @@ class CreateDocument extends Job // Upload attachment if ($this->request->file('attachment')) { - $media = $this->getMedia($this->request->file('attachment'), Str::plural($this->document->type)); + foreach ($this->request->file('attachment') as $attachment) { + $media = $this->getMedia($attachment, Str::plural($this->document->type)); - $this->document->attachMedia($media, 'attachment'); + $this->document->attachMedia($media, 'attachment'); + } } $this->dispatch(new CreateDocumentItemsAndTotals($this->document, $this->request)); diff --git a/app/Jobs/Document/UpdateDocument.php b/app/Jobs/Document/UpdateDocument.php index 86388ee41..6308a49cf 100644 --- a/app/Jobs/Document/UpdateDocument.php +++ b/app/Jobs/Document/UpdateDocument.php @@ -46,9 +46,13 @@ class UpdateDocument extends Job \DB::transaction(function () { // Upload attachment if ($this->request->file('attachment')) { - $media = $this->getMedia($this->request->file('attachment'), Str::plural($this->document->type)); + $this->document->delete_attachment(); - $this->document->attachMedia($media, 'attachment'); + foreach ($this->request->file('attachment') as $attachment) { + $media = $this->getMedia($attachment, Str::plural($this->document->type)); + + $this->document->attachMedia($media, 'attachment'); + } } $this->deleteRelationships($this->document, ['items', 'item_taxes', 'totals']); diff --git a/app/Models/Document/Document.php b/app/Models/Document/Document.php index e371395ce..b56390061 100644 --- a/app/Models/Document/Document.php +++ b/app/Models/Document/Document.php @@ -3,6 +3,7 @@ namespace App\Models\Document; use App\Abstracts\Model; +use App\Models\Common\Media as MediaModel; use App\Models\Setting\Tax; use App\Scopes\Document as Scope; use App\Traits\Currencies; @@ -224,7 +225,14 @@ class Document extends Model return false; } - return $this->getMedia('attachment')->last(); + return $this->getMedia('attachment')->all(); + } + + public function delete_attachment() + { + foreach ($this->attachment as $file) { + MediaModel::where('id', $file->id)->delete(); + } } /** diff --git a/resources/views/components/documents/form/advanced.blade.php b/resources/views/components/documents/form/advanced.blade.php index 1a9cf3449..29fd61854 100644 --- a/resources/views/components/documents/form/advanced.blade.php +++ b/resources/views/components/documents/form/advanced.blade.php @@ -20,18 +20,20 @@ @stack('recurring_row_end') @stack('more_row_start') - @if (!$hideCategory || !$hideAttachment) + @if (!$hideCategory)
@if (!$hideCategory) {{ Form::selectRemoteAddNewGroup('category_id', trans_choice('general.categories', 1), 'folder', $categories, $document->category_id ?? setting('default.' . $categoryType . '_category'), ['required' => 'required', 'path' => route('modals.categories.create') . '?type=' . $categoryType, 'remote_action' => route('categories.index'). '?search=type:' . $categoryType], $more_form_class) }} @endif - - @if (!$hideAttachment) - {{ Form::fileGroup('attachment', trans('general.attachment'), '', ['dropzone-class' => 'form-file'], null, $more_form_class) }} - @endif
@endif @stack('more_row_end') + + @if (!$hideAttachment) +
+ {{ Form::fileGroup('attachment', trans('general.attachment'), '', ['dropzone-class' => 'w-100', 'options' => ['maxFiles' => '10', ''], 'multiple' => 'multiple', 'isPreviewSingle' => 'false'], null, 'col-md-12') }} +
+ @endif diff --git a/resources/views/components/documents/show/attachment.blade.php b/resources/views/components/documents/show/attachment.blade.php index db5d27642..6ab858a27 100644 --- a/resources/views/components/documents/show/attachment.blade.php +++ b/resources/views/components/documents/show/attachment.blade.php @@ -1,11 +1,9 @@ @if ($attachment) -
-
- @php - $file = $attachment; - @endphp - - @include('partials.media.file') -
+
+ @foreach ($attachment as $file) +
+ @include('partials.media.file') +
+ @endforeach
@endif diff --git a/resources/views/partials/form/file_group.blade.php b/resources/views/partials/form/file_group.blade.php index 512f80528..dc808def6 100644 --- a/resources/views/partials/form/file_group.blade.php +++ b/resources/views/partials/form/file_group.blade.php @@ -26,7 +26,7 @@ @if (!empty($attributes['multiple'])) multiple @endif - @if (!empty($attributes['isPreviewSingle'])) + @if (isset($attributes['isPreviewSingle'])) :is-preview-single="{{ $attributes['isPreviewSingle'] }}" @endif v-model="{{ !empty($attributes['v-model']) ? $attributes['v-model'] : (!empty($attributes['data-field']) ? 'form.' . $attributes['data-field'] . '.'. $name : 'form.' . $name) }}"