added item events
This commit is contained in:
parent
67969d0710
commit
6af4c7553d
|
|
@ -0,0 +1,21 @@
|
|||
<?php
|
||||
|
||||
namespace App\Events\Common;
|
||||
|
||||
use App\Abstracts\Event;
|
||||
use App\Models\Common\Item;
|
||||
|
||||
class ItemCreated extends Event
|
||||
{
|
||||
public $item;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*
|
||||
* @param $item
|
||||
*/
|
||||
public function __construct(Item $item)
|
||||
{
|
||||
$this->item = $item;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
<?php
|
||||
|
||||
namespace App\Events\Common;
|
||||
|
||||
use App\Abstracts\Event;
|
||||
|
||||
class ItemCreating 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\Common;
|
||||
|
||||
use App\Abstracts\Event;
|
||||
|
||||
class ItemDeleted extends Event
|
||||
{
|
||||
public $item;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*
|
||||
* @param $item
|
||||
*/
|
||||
public function __construct($item)
|
||||
{
|
||||
$this->item = $item;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
<?php
|
||||
|
||||
namespace App\Events\Common;
|
||||
|
||||
use App\Abstracts\Event;
|
||||
|
||||
class ItemDeleting extends Event
|
||||
{
|
||||
public $item;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*
|
||||
* @param $item
|
||||
*/
|
||||
public function __construct($item)
|
||||
{
|
||||
$this->item = $item;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
<?php
|
||||
|
||||
namespace App\Events\Common;
|
||||
|
||||
use App\Abstracts\Event;
|
||||
use App\Models\Common\Item;
|
||||
|
||||
class ItemUpdated extends Event
|
||||
{
|
||||
public $item;
|
||||
|
||||
public $request;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*
|
||||
* @param $item
|
||||
* @param $request
|
||||
*/
|
||||
public function __construct(Item $item, $request)
|
||||
{
|
||||
$this->item = $item;
|
||||
$this->request = $request;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
<?php
|
||||
|
||||
namespace App\Events\Common;
|
||||
|
||||
use App\Abstracts\Event;
|
||||
use App\Models\Common\Item;
|
||||
|
||||
class ItemUpdating extends Event
|
||||
{
|
||||
public $item;
|
||||
|
||||
public $request;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*
|
||||
* @param $item
|
||||
* @param $request
|
||||
*/
|
||||
public function __construct(Item $item, $request)
|
||||
{
|
||||
$this->item = $item;
|
||||
$this->request = $request;
|
||||
}
|
||||
}
|
||||
|
|
@ -3,6 +3,8 @@
|
|||
namespace App\Jobs\Common;
|
||||
|
||||
use App\Abstracts\Job;
|
||||
use App\Events\Common\ItemCreated;
|
||||
use App\Events\Common\ItemCreating;
|
||||
use App\Interfaces\Job\HasOwner;
|
||||
use App\Interfaces\Job\HasSource;
|
||||
use App\Interfaces\Job\ShouldCreate;
|
||||
|
|
@ -13,6 +15,8 @@ class CreateItem extends Job implements HasOwner, HasSource, ShouldCreate
|
|||
{
|
||||
public function handle(): Item
|
||||
{
|
||||
event(new ItemCreating($this->request));
|
||||
|
||||
\DB::transaction(function () {
|
||||
$this->model = Item::create($this->request->all());
|
||||
|
||||
|
|
@ -26,6 +30,8 @@ class CreateItem extends Job implements HasOwner, HasSource, ShouldCreate
|
|||
$this->dispatch(new CreateItemTaxes($this->model, $this->request));
|
||||
});
|
||||
|
||||
event(new ItemCreated($this->model, $this->request));
|
||||
|
||||
return $this->model;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,6 +3,8 @@
|
|||
namespace App\Jobs\Common;
|
||||
|
||||
use App\Abstracts\Job;
|
||||
use App\Events\Common\ItemDeleted;
|
||||
use App\Events\Common\ItemDeleting;
|
||||
use App\Interfaces\Job\ShouldDelete;
|
||||
|
||||
class DeleteItem extends Job implements ShouldDelete
|
||||
|
|
@ -11,12 +13,16 @@ class DeleteItem extends Job implements ShouldDelete
|
|||
{
|
||||
$this->authorize();
|
||||
|
||||
event(new ItemDeleting($this->model));
|
||||
|
||||
\DB::transaction(function () {
|
||||
$this->deleteRelationships($this->model, ['taxes']);
|
||||
|
||||
$this->model->delete();
|
||||
});
|
||||
|
||||
event(new ItemDeleted($this->model));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,8 @@
|
|||
namespace App\Jobs\Common;
|
||||
|
||||
use App\Abstracts\Job;
|
||||
use App\Events\Common\ItemUpdated;
|
||||
use App\Events\Common\ItemUpdating;
|
||||
use App\Interfaces\Job\ShouldUpdate;
|
||||
use App\Jobs\Common\CreateItemTaxes;
|
||||
use App\Models\Common\Item;
|
||||
|
|
@ -11,6 +13,8 @@ class UpdateItem extends Job implements ShouldUpdate
|
|||
{
|
||||
public function handle(): Item
|
||||
{
|
||||
event(new ItemUpdating($this->model, $this->request));
|
||||
|
||||
\DB::transaction(function () {
|
||||
$this->model->update($this->request->all());
|
||||
|
||||
|
|
@ -26,6 +30,8 @@ class UpdateItem extends Job implements ShouldUpdate
|
|||
$this->dispatch(new CreateItemTaxes($this->model, $this->request));
|
||||
});
|
||||
|
||||
event(new ItemUpdated($this->model, $this->request));
|
||||
|
||||
return $this->model;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue