Skip to content

Commit

Permalink
use listener to clear cache
Browse files Browse the repository at this point in the history
  • Loading branch information
denisdulici committed Oct 12, 2023
1 parent 11a2e97 commit 6655204
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 9 deletions.
5 changes: 0 additions & 5 deletions app/Jobs/Auth/DeleteUser.php
Expand Up @@ -6,12 +6,9 @@
use App\Events\Auth\UserDeleted;
use App\Events\Auth\UserDeleting;
use App\Interfaces\Job\ShouldDelete;
use App\Traits\Plans;

class DeleteUser extends Job implements ShouldDelete
{
use Plans;

public function handle(): bool
{
$this->authorize();
Expand All @@ -26,8 +23,6 @@ public function handle(): bool
$this->model->flushCache();
});

$this->clearPlansCache();

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

return true;
Expand Down
5 changes: 1 addition & 4 deletions app/Jobs/Common/DeleteCompany.php
Expand Up @@ -6,12 +6,11 @@
use App\Events\Common\CompanyDeleted;
use App\Events\Common\CompanyDeleting;
use App\Interfaces\Job\ShouldDelete;
use App\Traits\Plans;
use App\Traits\Users;

class DeleteCompany extends Job implements ShouldDelete
{
use Plans, Users;
use Users;

protected $current_company_id;

Expand All @@ -36,8 +35,6 @@ public function handle(): bool
$this->model->delete();
});

$this->clearPlansCache();

event(new CompanyDeleted($this->model, $this->current_company_id));

company($this->current_company_id)->makeCurrent();
Expand Down
26 changes: 26 additions & 0 deletions app/Listeners/Common/ClearPlansCache.php
@@ -0,0 +1,26 @@
<?php

namespace App\Listeners\Common;

use App\Events\Auth\UserDeleted;
use App\Events\Common\CompanyDeleted;
use App\Traits\Plans;
use Illuminate\Events\Dispatcher;

class ClearPlansCache
{
use Plans;

public function handle(string $event): void
{
$this->clearPlansCache();
}

public function subscribe(Dispatcher $events): array
{
return [
UserDeleted::class => 'handle',
CompanyDeleted::class => 'handle',
];
}
}
1 change: 1 addition & 0 deletions app/Providers/Event.php
Expand Up @@ -128,6 +128,7 @@ class Event extends Provider
* @var array
*/
protected $subscribe = [
'App\Listeners\Common\ClearPlansCache',
'App\Listeners\Module\ClearCache',
'App\Listeners\Report\AddAccounts',
'App\Listeners\Report\AddCustomers',
Expand Down

0 comments on commit 6655204

Please sign in to comment.