From ae6742575dfdbd63f04a60fc06d657f32311937a Mon Sep 17 00:00:00 2001 From: "allen.yan" Date: Wed, 4 Jun 2025 16:11:45 +0800 Subject: [PATCH] =?UTF-8?q?sendSwitch=20=E5=95=8F=E9=A1=8C=20=E6=94=B9?= =?UTF-8?q?=E7=94=A8=20room=5Fname=20=3D=20PC101?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Controllers/RoomControlController.php | 15 +++++++++++---- app/Livewire/Admin/RoomDetailModal.php | 7 ++++--- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/app/Http/Controllers/RoomControlController.php b/app/Http/Controllers/RoomControlController.php index c7c0d9f..6fd2287 100644 --- a/app/Http/Controllers/RoomControlController.php +++ b/app/Http/Controllers/RoomControlController.php @@ -258,10 +258,17 @@ class RoomControlController extends Controller { $validated = $request->validated(); $branch = Branch::where('name',$validated['branch_name'])->first(); - $room = Room::where([ - ['branch_id', $branch->id], - ['name', $validated['room_name']], - ])->first(); + $roomType = null; + $roomName = null; + // 從 room_name(例如 PC101, SVR01)中擷取 type 與 name + if (preg_match('/^([A-Za-z]+)(\d+)$/', $validated['room_name'], $matches)) { + $roomType = strtolower($matches[1]); // 'PC' → 'pc' + $roomName = $matches[2]; // '101' + } + $room = Room::where('branch_id', $branch->id) + ->where('name', $roomName) + ->where('type', $roomType) + ->first(); if (!$room) { return ApiResponse::error('房間不存在'); diff --git a/app/Livewire/Admin/RoomDetailModal.php b/app/Livewire/Admin/RoomDetailModal.php index 1cadde0..ee4c453 100644 --- a/app/Livewire/Admin/RoomDetailModal.php +++ b/app/Livewire/Admin/RoomDetailModal.php @@ -20,13 +20,14 @@ class RoomDetailModal extends Component 'openAccountNotify','closeAccountNotify' ]; - public $room; + public $room_name; public $branch; public bool $showModal = false; public function openModal($roomId) { - $this->room = Room::find($roomId); + $room = Room::find($roomId); + $this->room_name=$room->type->value . $room->name; $this->branch = Branch::find($this->room->branch_id); $this->showModal = true; } @@ -69,7 +70,7 @@ class RoomDetailModal extends Component return [ 'branch_name' => $this->branch->name ?? '', - 'room_name' => $this->room->name ?? '', + 'room_name' => $this->room_name ?? '', 'command' => $command, 'started_at' => $startedAt ? $startedAt->toDateTimeString() : null, 'ended_at' => $endedAt ? $endedAt->toDateTimeString() : null,