2024-08-29 23:50:29 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App;
|
2024-08-30 09:37:24 +02:00
|
|
|
|
2024-08-29 23:50:29 +02:00
|
|
|
use App\Models\History;
|
|
|
|
|
|
|
|
class HistoryObserver
|
|
|
|
{
|
|
|
|
public function created($model)
|
|
|
|
{
|
|
|
|
History::create([
|
|
|
|
'model_id' => $model->id,
|
|
|
|
'model_name' => $model->getTable(),
|
2024-08-30 00:10:05 +02:00
|
|
|
'before' => [],
|
2024-08-29 23:50:29 +02:00
|
|
|
'after' => $model->toArray(),
|
|
|
|
'action' => HistoryAction::Insert,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function updating($model)
|
|
|
|
{
|
|
|
|
History::create([
|
|
|
|
'model_id' => $model->id,
|
|
|
|
'model_name' => $model->getTable(),
|
|
|
|
'before' => $model->getRawOriginal(),
|
|
|
|
'after' => $model->getAttributes(),
|
|
|
|
'action' => HistoryAction::Update,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function deleting($model)
|
|
|
|
{
|
|
|
|
History::create([
|
|
|
|
'model_id' => $model->id,
|
|
|
|
'model_name' => $model->getTable(),
|
|
|
|
'before' => $model->getRawOriginal(),
|
2024-08-30 00:10:05 +02:00
|
|
|
'after' => [],
|
2024-08-29 23:50:29 +02:00
|
|
|
'action' => HistoryAction::Delete,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|