202508221007
修正updated_at 不寫記錄
This commit is contained in:
parent
680a388e89
commit
9721325bbb
@ -24,8 +24,8 @@ class RoomObserver
|
||||
*/
|
||||
public function updated(Room $room): void
|
||||
{
|
||||
// 檢查是否有變更狀態
|
||||
if ($room->wasChanged(array_diff(array_keys($room->getChanges()), ['updated_at']))) {
|
||||
// 如果有變動才記錄
|
||||
if ($this->hasChangesExcept($room, ['updated_at'])) {
|
||||
$this->createStatusLog($room);
|
||||
}
|
||||
if ($room->isDirty('status')) {
|
||||
@ -69,6 +69,14 @@ class RoomObserver
|
||||
);
|
||||
$this->createStatusLog($room,$message);
|
||||
}
|
||||
protected function hasChangesExcept($model, array $except = ['updated_at']): bool
|
||||
{
|
||||
$changes = $model->getChanges();
|
||||
foreach ($except as $key) {
|
||||
unset($changes[$key]);
|
||||
}
|
||||
return !empty($changes);
|
||||
}
|
||||
|
||||
/**
|
||||
* 建立 RoomStatusLog
|
||||
|
Loading…
x
Reference in New Issue
Block a user