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_id' => 'required|integer',
|
||||||
'contact_name' => 'required|string',
|
'contact_name' => 'required|string',
|
||||||
'category_id' => 'required|integer',
|
'category_id' => 'required|integer',
|
||||||
'attachment' => $attachment,
|
'attachment.*' => $attachment,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,10 +43,12 @@ class CreateDocument extends Job
|
|||||||
|
|
||||||
// Upload attachment
|
// Upload attachment
|
||||||
if ($this->request->file('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));
|
$this->dispatch(new CreateDocumentItemsAndTotals($this->document, $this->request));
|
||||||
|
|
||||||
|
@ -46,10 +46,14 @@ class UpdateDocument extends Job
|
|||||||
\DB::transaction(function () {
|
\DB::transaction(function () {
|
||||||
// Upload attachment
|
// Upload attachment
|
||||||
if ($this->request->file('attachment')) {
|
if ($this->request->file('attachment')) {
|
||||||
$media = $this->getMedia($this->request->file('attachment'), Str::plural($this->document->type));
|
$this->document->delete_attachment();
|
||||||
|
|
||||||
|
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->deleteRelationships($this->document, ['items', 'item_taxes', 'totals']);
|
$this->deleteRelationships($this->document, ['items', 'item_taxes', 'totals']);
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
namespace App\Models\Document;
|
namespace App\Models\Document;
|
||||||
|
|
||||||
use App\Abstracts\Model;
|
use App\Abstracts\Model;
|
||||||
|
use App\Models\Common\Media as MediaModel;
|
||||||
use App\Models\Setting\Tax;
|
use App\Models\Setting\Tax;
|
||||||
use App\Scopes\Document as Scope;
|
use App\Scopes\Document as Scope;
|
||||||
use App\Traits\Currencies;
|
use App\Traits\Currencies;
|
||||||
@ -224,7 +225,14 @@ class Document extends Model
|
|||||||
return false;
|
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('recurring_row_end')
|
||||||
|
|
||||||
@stack('more_row_start')
|
@stack('more_row_start')
|
||||||
@if (!$hideCategory || !$hideAttachment)
|
@if (!$hideCategory)
|
||||||
<div class="{{ $more_class }}">
|
<div class="{{ $more_class }}">
|
||||||
@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) }}
|
{{ 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
|
@endif
|
||||||
|
|
||||||
@if (!$hideAttachment)
|
|
||||||
{{ Form::fileGroup('attachment', trans('general.attachment'), '', ['dropzone-class' => 'form-file'], null, $more_form_class) }}
|
|
||||||
@endif
|
|
||||||
</div>
|
</div>
|
||||||
@endif
|
@endif
|
||||||
@stack('more_row_end')
|
@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>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -1,11 +1,9 @@
|
|||||||
@if ($attachment)
|
@if ($attachment)
|
||||||
<div class="row align-items-center mb-4">
|
<div class="row align-items-center">
|
||||||
<div class="col-xs-12 col-sm-4">
|
@foreach ($attachment as $file)
|
||||||
@php
|
<div class="col-xs-12 col-sm-4 mb-4">
|
||||||
$file = $attachment;
|
|
||||||
@endphp
|
|
||||||
|
|
||||||
@include('partials.media.file')
|
@include('partials.media.file')
|
||||||
</div>
|
</div>
|
||||||
|
@endforeach
|
||||||
</div>
|
</div>
|
||||||
@endif
|
@endif
|
||||||
|
@ -26,7 +26,7 @@
|
|||||||
@if (!empty($attributes['multiple']))
|
@if (!empty($attributes['multiple']))
|
||||||
multiple
|
multiple
|
||||||
@endif
|
@endif
|
||||||
@if (!empty($attributes['isPreviewSingle']))
|
@if (isset($attributes['isPreviewSingle']))
|
||||||
:is-preview-single="{{ $attributes['isPreviewSingle'] }}"
|
:is-preview-single="{{ $attributes['isPreviewSingle'] }}"
|
||||||
@endif
|
@endif
|
||||||
v-model="{{ !empty($attributes['v-model']) ? $attributes['v-model'] : (!empty($attributes['data-field']) ? 'form.' . $attributes['data-field'] . '.'. $name : 'form.' . $name) }}"
|
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