add document attachment multiple
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user