added currency events
This commit is contained in:
parent
6af4c7553d
commit
9edf50f9ea
|
|
@ -0,0 +1,24 @@
|
|||
<?php
|
||||
|
||||
namespace App\Events\Setting;
|
||||
|
||||
use App\Abstracts\Event;
|
||||
|
||||
class CurrencyCreated extends Event
|
||||
{
|
||||
public $currency;
|
||||
|
||||
public $request;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*
|
||||
* @param $currency
|
||||
* @param $request
|
||||
*/
|
||||
public function __construct($currency, $request)
|
||||
{
|
||||
$this->currency = $currency;
|
||||
$this->request = $request;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
<?php
|
||||
|
||||
namespace App\Events\Setting;
|
||||
|
||||
use App\Abstracts\Event;
|
||||
|
||||
class CurrencyCreating extends Event
|
||||
{
|
||||
public $request;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*
|
||||
* @param $request
|
||||
*/
|
||||
public function __construct($request)
|
||||
{
|
||||
$this->request = $request;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
<?php
|
||||
|
||||
namespace App\Events\Setting;
|
||||
|
||||
use App\Abstracts\Event;
|
||||
|
||||
class CurrencyDeleted extends Event
|
||||
{
|
||||
public $currency;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*
|
||||
* @param $currency
|
||||
*/
|
||||
public function __construct($currency)
|
||||
{
|
||||
$this->currency = $currency;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
<?php
|
||||
|
||||
namespace App\Events\Setting;
|
||||
|
||||
use App\Abstracts\Event;
|
||||
|
||||
class CurrencyDeleting extends Event
|
||||
{
|
||||
public $currency;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*
|
||||
* @param $currency
|
||||
*/
|
||||
public function __construct($currency)
|
||||
{
|
||||
$this->currency = $currency;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
<?php
|
||||
|
||||
namespace App\Events\Setting;
|
||||
|
||||
use App\Abstracts\Event;
|
||||
|
||||
class CurrencyUpdated extends Event
|
||||
{
|
||||
public $currency;
|
||||
|
||||
public $request;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*
|
||||
* @param $currency
|
||||
* @param $request
|
||||
*/
|
||||
public function __construct($currency, $request)
|
||||
{
|
||||
$this->currency = $currency;
|
||||
$this->request = $request;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
<?php
|
||||
|
||||
namespace App\Events\Setting;
|
||||
|
||||
use App\Abstracts\Event;
|
||||
|
||||
class CurrencyUpdating extends Event
|
||||
{
|
||||
public $currency;
|
||||
|
||||
public $request;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*
|
||||
* @param $currency
|
||||
* @param $request
|
||||
*/
|
||||
public function __construct($currency, $request)
|
||||
{
|
||||
$this->currency = $currency;
|
||||
$this->request = $request;
|
||||
}
|
||||
}
|
||||
|
|
@ -3,6 +3,8 @@
|
|||
namespace App\Jobs\Setting;
|
||||
|
||||
use App\Abstracts\Job;
|
||||
use App\Events\Setting\CurrencyCreated;
|
||||
use App\Events\Setting\CurrencyCreating;
|
||||
use App\Interfaces\Job\HasOwner;
|
||||
use App\Interfaces\Job\HasSource;
|
||||
use App\Interfaces\Job\ShouldCreate;
|
||||
|
|
@ -12,6 +14,8 @@ class CreateCurrency extends Job implements HasOwner, HasSource, ShouldCreate
|
|||
{
|
||||
public function handle(): Currency
|
||||
{
|
||||
event(new CurrencyCreating($this->request));
|
||||
|
||||
// Force the rate to be 1 for default currency
|
||||
if ($this->request->get('default_currency')) {
|
||||
$this->request['rate'] = '1';
|
||||
|
|
@ -27,6 +31,8 @@ class CreateCurrency extends Job implements HasOwner, HasSource, ShouldCreate
|
|||
}
|
||||
});
|
||||
|
||||
event(new CurrencyCreated($this->model, $this->request));
|
||||
|
||||
return $this->model;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,8 @@
|
|||
namespace App\Jobs\Setting;
|
||||
|
||||
use App\Abstracts\Job;
|
||||
use App\Events\Setting\CurrencyDeleted;
|
||||
use App\Events\Setting\CurrencyDeleting;
|
||||
use App\Interfaces\Job\ShouldDelete;
|
||||
|
||||
class DeleteCurrency extends Job implements ShouldDelete
|
||||
|
|
@ -11,10 +13,14 @@ class DeleteCurrency extends Job implements ShouldDelete
|
|||
{
|
||||
$this->authorize();
|
||||
|
||||
event(new CurrencyDeleting($this->model));
|
||||
|
||||
\DB::transaction(function () {
|
||||
$this->model->delete();
|
||||
});
|
||||
|
||||
event(new CurrencyDeleted($this->model));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,8 @@
|
|||
namespace App\Jobs\Setting;
|
||||
|
||||
use App\Abstracts\Job;
|
||||
use App\Events\Setting\CurrencyUpdated;
|
||||
use App\Events\Setting\CurrencyUpdating;
|
||||
use App\Interfaces\Job\ShouldUpdate;
|
||||
use App\Models\Setting\Currency;
|
||||
|
||||
|
|
@ -12,6 +14,8 @@ class UpdateCurrency extends Job implements ShouldUpdate
|
|||
{
|
||||
$this->authorize();
|
||||
|
||||
event(new CurrencyUpdating($this->model, $this->request));
|
||||
|
||||
// Force the rate to be 1 for default currency
|
||||
if ($this->request->get('default_currency')) {
|
||||
$this->request['rate'] = '1';
|
||||
|
|
@ -27,6 +31,8 @@ class UpdateCurrency extends Job implements ShouldUpdate
|
|||
}
|
||||
});
|
||||
|
||||
event(new CurrencyUpdated($this->model, $this->request));
|
||||
|
||||
return $this->model;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue