From b9d7dfb694966013841cebf8dff1289dbaa13615 Mon Sep 17 00:00:00 2001 From: "allen.yan" Date: Fri, 23 May 2025 09:37:04 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AA=BF=E6=95=B4=E5=BF=83=E8=B7=B3=E5=B0=81?= =?UTF-8?q?=E5=8C=85=20=E9=82=8F=E8=BC=AF=20=E6=94=B9=E5=9B=9E=E7=94=A8bra?= =?UTF-8?q?nch=5Fname=20=E5=8E=BB=E9=A9=97=E8=A8=BC=2020250523?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Controllers/RoomControlController.php | 6 ++++-- app/Http/Requests/ReceiveRoomRegisterRequest.php | 4 ++-- app/Http/Requests/ReceiveRoomStatusDataRequest.php | 6 +++--- app/Models/MachineStatus.php | 4 ++-- .../2025_05_21_170205_create_machine_statuses_table.php | 2 +- 5 files changed, 12 insertions(+), 10 deletions(-) diff --git a/app/Http/Controllers/RoomControlController.php b/app/Http/Controllers/RoomControlController.php index 1af64c6..272c2c7 100644 --- a/app/Http/Controllers/RoomControlController.php +++ b/app/Http/Controllers/RoomControlController.php @@ -103,7 +103,8 @@ class RoomControlController extends Controller $roomType = strtolower($matches[1]); // 'PC' → 'pc' $roomName = $matches[2]; // '101' } - $room = Room::where('branch_id', $validated['branch_id']) + $branch=Branch::where('name',$validated['branch_name'])->first(); + $room = Room::where('branch_id', $branch->id) ->where('name', $roomName) ->where('type', $roomType) ->first(); @@ -183,7 +184,8 @@ class RoomControlController extends Controller $roomType = strtolower($matches[1]); // 'PC' → 'pc' $roomName = $matches[2]; // '101' } - $room = Room::where('branch', $validated['branch_id']) + $branch=Branch::where('name',$validated['branch_name'])->first(); + $room = Room::where('branch', $branch->id) ->where('name', $roomName) ->where('type', $roomType) ->first(); diff --git a/app/Http/Requests/ReceiveRoomRegisterRequest.php b/app/Http/Requests/ReceiveRoomRegisterRequest.php index a9af873..21f4710 100644 --- a/app/Http/Requests/ReceiveRoomRegisterRequest.php +++ b/app/Http/Requests/ReceiveRoomRegisterRequest.php @@ -8,7 +8,7 @@ use Illuminate\Foundation\Http\FormRequest; * @OA\Schema( * schema="ReceiveRoomRegisterRequest", * required={"branch", "room_name", "email" ,"password"}, - * @OA\Property(property="branch", type="string", example="1"), + * @OA\Property(property="branch_name", type="string", example="測試"), * @OA\Property(property="room_name", type="string", example="PC101"), * @OA\Property(property="room_ip", type="string", example="192.168.1.1"), * @OA\Property(property="email", type="string", example="XX@gmail.com"), @@ -25,7 +25,7 @@ class ReceiveRoomRegisterRequest extends ApiRequest public function rules(): array { return [ - 'branch' => 'required|string', + 'branch_name' =>'required|string|exists:branches,name', 'room_name' => 'required|string', 'room_ip' => 'required|string', 'email' => 'required|email', diff --git a/app/Http/Requests/ReceiveRoomStatusDataRequest.php b/app/Http/Requests/ReceiveRoomStatusDataRequest.php index a369955..ae90d82 100644 --- a/app/Http/Requests/ReceiveRoomStatusDataRequest.php +++ b/app/Http/Requests/ReceiveRoomStatusDataRequest.php @@ -7,8 +7,8 @@ use Illuminate\Foundation\Http\FormRequest; /** * @OA\Schema( * schema="ReceiveRoomStatusDataRequest", - * required={"branch","hostname", "ip", "status"}, - * @OA\Property(property="branch", type="string", example="1"), + * required={"branch_name","hostname", "ip", "status"}, + * @OA\Property(property="branch_name", type="string", example="測試"), * @OA\Property(property="hostname", type="string", example="PC101"), * @OA\Property(property="ip", type="string", example="192.168.XX.XX"), * @OA\Property(property="cpu", type="numeric", example="0.00"), @@ -26,7 +26,7 @@ class ReceiveRoomStatusDataRequest extends ApiRequest public function rules(): array { return [ - 'branch' =>'required|string', + 'branch_name' =>'required|string|exists:branches,name', 'hostname' => 'required|string', 'ip' => 'required|string', 'cpu' => 'nullable|numeric', diff --git a/app/Models/MachineStatus.php b/app/Models/MachineStatus.php index 0784c26..fd9f19b 100644 --- a/app/Models/MachineStatus.php +++ b/app/Models/MachineStatus.php @@ -8,7 +8,7 @@ use Illuminate\Database\Eloquent\Model; * @OA\Schema( * schema="MachineStatus", * type="object", - * @OA\Property(property="branch", type="string", example="測試"), + * @OA\Property(property="branch_name", type="string", example="測試"), * @OA\Property(property="hostname", type="string", example="PC101"), * @OA\Property(property="ip", type="string", example="192.168.XX.XX"), * @OA\Property(property="cpu", type="numeric", example="0.00"), @@ -20,7 +20,7 @@ use Illuminate\Database\Eloquent\Model; class MachineStatus extends Model { protected $fillable = [ - 'branch', + 'branch_name', 'hostname', 'ip', 'cpu', diff --git a/database/migrations/2025_05_21_170205_create_machine_statuses_table.php b/database/migrations/2025_05_21_170205_create_machine_statuses_table.php index e134114..8833ab7 100644 --- a/database/migrations/2025_05_21_170205_create_machine_statuses_table.php +++ b/database/migrations/2025_05_21_170205_create_machine_statuses_table.php @@ -13,7 +13,7 @@ return new class extends Migration { Schema::create('machine_statuses', function (Blueprint $table) { $table->id(); - $table->string('branch'); + $table->string('branch_name'); $table->string('hostname'); $table->string('ip')->nullable(); $table->decimal('cpu', 5, 2)->nullable();