Files
sam-api/app/Observers/TodayIssue/StockIssueObserver.php

44 lines
1.0 KiB
PHP
Raw Permalink Normal View History

<?php
namespace App\Observers\TodayIssue;
use App\Models\Tenants\Stock;
use App\Services\TodayIssueObserverService;
use Illuminate\Support\Facades\Log;
/**
* Stock 모델의 TodayIssue Observer
*/
class StockIssueObserver
{
public function __construct(
protected TodayIssueObserverService $service
) {}
public function created(Stock $stock): void
{
$this->safeExecute(fn () => $this->service->handleStockChange($stock));
}
public function updated(Stock $stock): void
{
$this->safeExecute(fn () => $this->service->handleStockChange($stock));
}
public function deleted(Stock $stock): void
{
$this->safeExecute(fn () => $this->service->handleStockDeleted($stock));
}
protected function safeExecute(callable $callback): void
{
try {
$callback();
} catch (\Throwable $e) {
Log::warning('TodayIssue StockObserver failed', [
'error' => $e->getMessage(),
]);
}
}
}