Files
ntspi-app/app/Observers/UserObserver.php
F4ilji c01016a154 Migrate backend to Porto architecture and fix minor bugs
- Fully transitioned the backend to the Porto architectural pattern
- Improved code organization and maintainability
- Fixed minor bugs and inconsistencies
2025-05-12 08:47:43 +05:00

59 lines
1.3 KiB
PHP

<?php
namespace App\Observers;
use App\Containers\User\Models\User;
use App\Services\App\Cache\UserCacheService;
class UserObserver
{
private UserCacheService $userCacheService;
public function __construct()
{
$this->userCacheService = app(UserCacheService::class);
}
/**
* Handle the User "created" event.
*/
public function created(User $user): void
{
$this->userCacheService->clearAllCacheByModel();
}
/**
* Handle the User "updated" event.
*/
public function updated(User $user): void
{
$this->userCacheService->clearCache($user);
$this->userCacheService->clearAllCacheByModel();
}
/**
* Handle the User "deleted" event.
*/
public function deleted(User $user): void
{
$this->userCacheService->clearCache($user);
$this->userCacheService->clearAllCacheByModel();
}
/**
* Handle the User "restored" event.
*/
public function restored(User $user): void
{
$this->userCacheService->clearAllCacheByModel();
}
/**
* Handle the User "force deleted" event.
*/
public function forceDeleted(User $user): void
{
$this->userCacheService->clearCache($user);
$this->userCacheService->clearAllCacheByModel();
}
}