調整
updateOrCreate 不會新增的問題 20250717
This commit is contained in:
parent
3adc02ea55
commit
22610d61a5
@ -108,23 +108,33 @@ class RoomControlController extends Controller
|
|||||||
$validated['started_at'] = null;
|
$validated['started_at'] = null;
|
||||||
$validated['ended_at'] = null;
|
$validated['ended_at'] = null;
|
||||||
}
|
}
|
||||||
|
$room = Room::where([
|
||||||
$room = Room::updateOrCreate(
|
'branch_id' => $validated['branch_id'],
|
||||||
[
|
'floor' => $validated['floor'],
|
||||||
'branch_id' => $validated['branch_id'],
|
'type' => $validated['type'],
|
||||||
'floor' => $validated['floor'],
|
'name' => $validated['name'],
|
||||||
'type' => $validated['type'],
|
])->first();
|
||||||
'name' => $validated['name'],
|
if ($room) {
|
||||||
],
|
// 更新
|
||||||
[
|
$room->update([
|
||||||
//'internal_ip' => $validated['internal_ip'],
|
|
||||||
//'port' => $validated['port'],
|
|
||||||
'is_online' => $validated['is_online'],
|
'is_online' => $validated['is_online'],
|
||||||
'status' => $validated['status'],
|
'status' => $validated['status'],
|
||||||
'started_at' => $validated['started_at'],
|
'started_at' => $validated['started_at'],
|
||||||
'ended_at' => $validated['ended_at'],
|
'ended_at' => $validated['ended_at'],
|
||||||
]
|
]);
|
||||||
);
|
} else {
|
||||||
|
// 新增
|
||||||
|
$room = Room::create([
|
||||||
|
'branch_id' => $validated['branch_id'],
|
||||||
|
'floor' => $validated['floor'],
|
||||||
|
'type' => $validated['type'],
|
||||||
|
'name' => $validated['name'],
|
||||||
|
'is_online' => $validated['is_online'],
|
||||||
|
'status' => $validated['status'],
|
||||||
|
'started_at' => $validated['started_at'],
|
||||||
|
'ended_at' => $validated['ended_at'],
|
||||||
|
]);
|
||||||
|
}
|
||||||
return ApiResponse::success(new RoomResource($room->refresh()));
|
return ApiResponse::success(new RoomResource($room->refresh()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user