41 lines
983 B
PHP
41 lines
983 B
PHP
|
<?php
|
||
|
|
||
|
namespace App;
|
||
|
use App\Models\History;
|
||
|
|
||
|
class HistoryObserver
|
||
|
{
|
||
|
public function created($model)
|
||
|
{
|
||
|
History::create([
|
||
|
'model_id' => $model->id,
|
||
|
'model_name' => $model->getTable(),
|
||
|
'before' => null,
|
||
|
'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(),
|
||
|
'after' => null,
|
||
|
'action' => HistoryAction::Delete,
|
||
|
]);
|
||
|
}
|
||
|
}
|