Compare commits

...

3 Commits

Author SHA1 Message Date
9721325bbb 202508221007
修正updated_at 不寫記錄
2025-08-22 10:07:50 +08:00
680a388e89 202508220953
修正 updated_at 不寫記錄
2025-08-22 09:54:26 +08:00
bb1defcc98 Merge pull request 'test' (#1) from test into main
Reviewed-on: #1
2025-08-22 09:29:50 +08:00
2 changed files with 10 additions and 31 deletions

View File

@ -24,8 +24,8 @@ class RoomObserver
*/
public function updated(Room $room): void
{
// 檢查是否有變更狀態
if ($room->wasChanged()) {
// 如果有變動才記錄
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

View File

@ -1,29 +0,0 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('FavoriteSongs', function (Blueprint $table) {
$table->id();
$table->string('songNumber',20);
$table->string('userPhone', 10);
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('FavoriteSongs');
}
};