akaunting/app/Jobs/Common/UpdateItem.php

47 lines
908 B
PHP
Raw Normal View History

2019-11-16 10:21:14 +03:00
<?php
namespace App\Jobs\Common;
use App\Abstracts\Job;
use App\Models\Common\Item;
class UpdateItem extends Job
{
protected $item;
protected $request;
/**
* Create a new job instance.
*
* @param $item
* @param $request
*/
public function __construct($item, $request)
{
$this->item = $item;
$this->request = $this->getRequestInstance($request);
}
/**
* Execute the job.
*
* @return Item
*/
public function handle()
{
2020-06-26 13:40:19 +03:00
\DB::transaction(function () {
$this->item->update($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
2020-06-26 13:40:19 +03:00
$this->item->attachMedia($media, 'picture');
}
});
2019-11-16 10:21:14 +03:00
return $this->item;
}
}