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)