2019-11-16 10:21:14 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Jobs\Setting;
|
|
|
|
|
|
|
|
use App\Abstracts\Job;
|
|
|
|
use App\Models\Setting\Currency;
|
|
|
|
|
|
|
|
class CreateCurrency extends Job
|
|
|
|
{
|
2020-06-26 13:40:19 +03:00
|
|
|
protected $currency;
|
|
|
|
|
2019-11-16 10:21:14 +03:00
|
|
|
protected $request;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new job instance.
|
|
|
|
*
|
|
|
|
* @param $request
|
|
|
|
*/
|
|
|
|
public function __construct($request)
|
|
|
|
{
|
|
|
|
$this->request = $this->getRequestInstance($request);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Execute the job.
|
|
|
|
*
|
|
|
|
* @return Currency
|
|
|
|
*/
|
|
|
|
public function handle()
|
|
|
|
{
|
|
|
|
// Force the rate to be 1 for default currency
|
|
|
|
if ($this->request->get('default_currency')) {
|
|
|
|
$this->request['rate'] = '1';
|
|
|
|
}
|
|
|
|
|
2020-06-26 13:40:19 +03:00
|
|
|
\DB::transaction(function () {
|
|
|
|
$this->currency = Currency::create($this->request->all());
|
2019-11-16 10:21:14 +03:00
|
|
|
|
2020-06-26 13:40:19 +03:00
|
|
|
// Update default currency setting
|
|
|
|
if ($this->request->get('default_currency')) {
|
|
|
|
setting()->set('default.currency', $this->request->get('code'));
|
|
|
|
setting()->save();
|
|
|
|
}
|
|
|
|
});
|
2019-11-16 10:21:14 +03:00
|
|
|
|
2020-06-26 13:40:19 +03:00
|
|
|
return $this->currency;
|
2019-11-16 10:21:14 +03:00
|
|
|
}
|
|
|
|
}
|