akaunting/app/Jobs/Document/DuplicateDocument.php

31 lines
578 B
PHP
Raw Normal View History

2020-12-24 01:28:38 +03:00
<?php
namespace App\Jobs\Document;
use App\Abstracts\Job;
use App\Events\Document\DocumentCreated;
use App\Models\Document\Document;
class DuplicateDocument extends Job
{
protected $clone;
2021-09-06 11:53:57 +03:00
public function __construct(Document $model)
2020-12-24 01:28:38 +03:00
{
2021-09-06 11:53:57 +03:00
$this->model = $model;
parent::__construct($model);
2020-12-24 01:28:38 +03:00
}
2021-09-06 11:53:57 +03:00
public function handle(): Document
2020-12-24 01:28:38 +03:00
{
\DB::transaction(function () {
2021-09-06 11:53:57 +03:00
$this->clone = $this->model->duplicate();
2020-12-24 01:28:38 +03:00
});
event(new DocumentCreated($this->clone, request()));
2020-12-24 01:28:38 +03:00
return $this->clone;
}
}