2019-11-16 10:21:14 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Jobs\Common;
|
|
|
|
|
|
|
|
use App\Abstracts\Job;
|
2021-09-06 11:53:57 +03:00
|
|
|
use App\Interfaces\Job\HasOwner;
|
2021-09-07 10:33:34 +03:00
|
|
|
use App\Interfaces\Job\HasSource;
|
2021-09-06 11:53:57 +03:00
|
|
|
use App\Interfaces\Job\ShouldCreate;
|
2020-12-08 13:30:06 +03:00
|
|
|
use App\Jobs\Common\CreateItemTaxes;
|
2020-12-08 17:00:50 +03:00
|
|
|
use App\Models\Common\Item;
|
2019-11-16 10:21:14 +03:00
|
|
|
|
2021-09-07 10:33:34 +03:00
|
|
|
class CreateItem extends Job implements HasOwner, HasSource, ShouldCreate
|
2019-11-16 10:21:14 +03:00
|
|
|
{
|
2021-09-06 11:53:57 +03:00
|
|
|
public function handle(): Item
|
2019-11-16 10:21:14 +03:00
|
|
|
{
|
2020-06-26 13:40:19 +03:00
|
|
|
\DB::transaction(function () {
|
2021-09-06 11:53:57 +03:00
|
|
|
$this->model = Item::create($this->request->all());
|
2019-11-16 10:21:14 +03:00
|
|
|
|
2020-06-26 13:40:19 +03:00
|
|
|
// Upload picture
|
|
|
|
if ($this->request->file('picture')) {
|
|
|
|
$media = $this->getMedia($this->request->file('picture'), 'items');
|
2019-11-16 10:21:14 +03:00
|
|
|
|
2021-09-06 11:53:57 +03:00
|
|
|
$this->model->attachMedia($media, 'picture');
|
2020-06-26 13:40:19 +03:00
|
|
|
}
|
2020-12-08 13:30:06 +03:00
|
|
|
|
2021-09-06 11:53:57 +03:00
|
|
|
$this->dispatch(new CreateItemTaxes($this->model, $this->request));
|
2020-06-26 13:40:19 +03:00
|
|
|
});
|
2019-11-16 10:21:14 +03:00
|
|
|
|
2021-09-06 11:53:57 +03:00
|
|
|
return $this->model;
|
2019-11-16 10:21:14 +03:00
|
|
|
}
|
|
|
|
}
|