add document attachment multiple
This commit is contained in:
parent
e2a2723e28
commit
f13677e0a3
@ -61,7 +61,7 @@ class Document extends FormRequest
|
||||
'contact_id' => 'required|integer',
|
||||
'contact_name' => 'required|string',
|
||||
'category_id' => 'required|integer',
|
||||
'attachment' => $attachment,
|
||||
'attachment.*' => $attachment,
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -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));
|
||||
|
@ -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']);
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -20,18 +20,20 @@
|
||||
@stack('recurring_row_end')
|
||||
|
||||
@stack('more_row_start')
|
||||
@if (!$hideCategory || !$hideAttachment)
|
||||
@if (!$hideCategory)
|
||||
<div class="{{ $more_class }}">
|
||||
@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
|
||||
</div>
|
||||
@endif
|
||||
@stack('more_row_end')
|
||||
|
||||
@if (!$hideAttachment)
|
||||
<div class="col-md-12">
|
||||
{{ Form::fileGroup('attachment', trans('general.attachment'), '', ['dropzone-class' => 'w-100', 'options' => ['maxFiles' => '10', ''], 'multiple' => 'multiple', 'isPreviewSingle' => 'false'], null, 'col-md-12') }}
|
||||
</div>
|
||||
@endif
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -1,11 +1,9 @@
|
||||
@if ($attachment)
|
||||
<div class="row align-items-center mb-4">
|
||||
<div class="col-xs-12 col-sm-4">
|
||||
@php
|
||||
$file = $attachment;
|
||||
@endphp
|
||||
|
||||
@include('partials.media.file')
|
||||
</div>
|
||||
<div class="row align-items-center">
|
||||
@foreach ($attachment as $file)
|
||||
<div class="col-xs-12 col-sm-4 mb-4">
|
||||
@include('partials.media.file')
|
||||
</div>
|
||||
@endforeach
|
||||
</div>
|
||||
@endif
|
||||
|
@ -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) }}"
|
||||
|
Loading…
x
Reference in New Issue
Block a user