feat: initialize Dr-Panel project with patient file number support

This commit is contained in:
SajjadMahmoody
2026-05-06 02:18:23 +03:30
parent f8f174690a
commit 8b84d1780f
460 changed files with 113960 additions and 1 deletions
+74
View File
@@ -0,0 +1,74 @@
<?php
declare(strict_types=1);
namespace App\Observers;
use App\Models\SyncLog;
use Illuminate\Database\Eloquent\Model;
class SyncObserver
{
public function created(Model $model): void
{
if (app()->bound('sync.applying')) {
return;
}
SyncLog::create([
'datetime' => now(),
'ip' => request()->ip() ?? '127.0.0.1',
'user' => auth()->user()?->name ?? 'system',
'table_name' => $model->getTable(),
'action' => 'created',
'record_id' => $model->getKey(),
'changed_data' => $model->getAttributes(),
]);
}
public function updated(Model $model): void
{
if (app()->bound('sync.applying')) {
return;
}
$dirty = $model->getDirty();
if (empty($dirty)) {
return;
}
$changedData = [];
foreach ($dirty as $field => $rawValue) {
$changedData[$field] = $rawValue instanceof \BackedEnum
? $rawValue->value
: (is_object($rawValue) ? (string) $rawValue : $rawValue);
}
SyncLog::create([
'datetime' => now(),
'ip' => request()->ip() ?? '127.0.0.1',
'user' => auth()->user()?->name ?? 'system',
'table_name' => $model->getTable(),
'action' => 'updated',
'record_id' => $model->getKey(),
'changed_data' => $changedData,
]);
}
public function deleted(Model $model): void
{
if (app()->bound('sync.applying')) {
return;
}
SyncLog::create([
'datetime' => now(),
'ip' => request()->ip() ?? '127.0.0.1',
'user' => auth()->user()?->name ?? 'system',
'table_name' => $model->getTable(),
'action' => 'deleted',
'record_id' => $model->getKey(),
'changed_data' => null,
]);
}
}