Skip to content

Commit

Permalink
added tax events
Browse files Browse the repository at this point in the history
  • Loading branch information
CihanSenturk committed Oct 31, 2023
1 parent 9edf50f commit b9a0ba6
Show file tree
Hide file tree
Showing 9 changed files with 150 additions and 0 deletions.
24 changes: 24 additions & 0 deletions app/Events/Setting/TaxCreated.php
@@ -0,0 +1,24 @@
<?php

namespace App\Events\Setting;

use App\Abstracts\Event;

class TaxCreated extends Event
{
public $tax;

public $request;

/**
* Create a new event instance.
*
* @param $tax
* @param $request
*/
public function __construct($tax, $request)
{
$this->tax = $tax;
$this->request = $request;
}
}
20 changes: 20 additions & 0 deletions app/Events/Setting/TaxCreating.php
@@ -0,0 +1,20 @@
<?php

namespace App\Events\Setting;

use App\Abstracts\Event;

class TaxCreating extends Event
{
public $request;

/**
* Create a new event instance.
*
* @param $request
*/
public function __construct($request)
{
$this->request = $request;
}
}
20 changes: 20 additions & 0 deletions app/Events/Setting/TaxDeleted.php
@@ -0,0 +1,20 @@
<?php

namespace App\Events\Setting;

use App\Abstracts\Event;

class TaxDeleted extends Event
{
public $tax;

/**
* Create a new event instance.
*
* @param $tax
*/
public function __construct($tax)
{
$this->tax = $tax;
}
}
20 changes: 20 additions & 0 deletions app/Events/Setting/TaxDeleting.php
@@ -0,0 +1,20 @@
<?php

namespace App\Events\Setting;

use App\Abstracts\Event;

class TaxDeleting extends Event
{
public $tax;

/**
* Create a new event instance.
*
* @param $tax
*/
public function __construct($tax)
{
$this->tax = $tax;
}
}
24 changes: 24 additions & 0 deletions app/Events/Setting/TaxUpdated.php
@@ -0,0 +1,24 @@
<?php

namespace App\Events\Setting;

use App\Abstracts\Event;

class TaxUpdated extends Event
{
public $tax;

public $request;

/**
* Create a new event instance.
*
* @param $tax
* @param $request
*/
public function __construct($tax, $request)
{
$this->tax = $tax;
$this->request = $request;
}
}
24 changes: 24 additions & 0 deletions app/Events/Setting/TaxUpdating.php
@@ -0,0 +1,24 @@
<?php

namespace App\Events\Setting;

use App\Abstracts\Event;

class TaxUpdating extends Event
{
public $tax;

public $request;

/**
* Create a new event instance.
*
* @param $tax
* @param $request
*/
public function __construct($tax, $request)
{
$this->tax = $tax;
$this->request = $request;
}
}
6 changes: 6 additions & 0 deletions app/Jobs/Setting/CreateTax.php
Expand Up @@ -3,6 +3,8 @@
namespace App\Jobs\Setting;

use App\Abstracts\Job;
use App\Events\Setting\TaxCreated;
use App\Events\Setting\TaxCreating;
use App\Interfaces\Job\HasOwner;
use App\Interfaces\Job\HasSource;
use App\Interfaces\Job\ShouldCreate;
Expand All @@ -12,10 +14,14 @@ class CreateTax extends Job implements HasOwner, HasSource, ShouldCreate
{
public function handle(): Tax
{
event(new TaxCreating($this->request));

\DB::transaction(function () {
$this->model = Tax::create($this->request->all());
});

event(new TaxCreated($this->model, $this->request));

return $this->model;
}
}
6 changes: 6 additions & 0 deletions app/Jobs/Setting/DeleteTax.php
Expand Up @@ -3,6 +3,8 @@
namespace App\Jobs\Setting;

use App\Abstracts\Job;
use App\Events\Setting\TaxDeleted;
use App\Events\Setting\TaxDeleting;
use App\Interfaces\Job\ShouldDelete;

class DeleteTax extends Job implements ShouldDelete
Expand All @@ -11,10 +13,14 @@ public function handle(): bool
{
$this->authorize();

event(new TaxDeleting($this->model));

\DB::transaction(function () {
$this->model->delete();
});

event(new TaxDeleted($this->model));

return true;
}

Expand Down
6 changes: 6 additions & 0 deletions app/Jobs/Setting/UpdateTax.php
Expand Up @@ -3,6 +3,8 @@
namespace App\Jobs\Setting;

use App\Abstracts\Job;
use App\Events\Setting\TaxUpdated;
use App\Events\Setting\TaxUpdating;
use App\Interfaces\Job\ShouldUpdate;
use App\Models\Setting\Tax;

Expand All @@ -12,10 +14,14 @@ public function handle(): Tax
{
$this->authorize();

event(new TaxUpdating($this->model, $this->request));

\DB::transaction(function () {
$this->model->update($this->request->all());
});

event(new TaxUpdated($this->model, $this->request));

return $this->model;
}

Expand Down

0 comments on commit b9a0ba6

Please sign in to comment.