From 9fc3e97ea314e3a427b156897f41b1243f8f0c8e Mon Sep 17 00:00:00 2001 From: "iVampireSP.com" Date: Mon, 21 Nov 2022 12:42:47 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E8=BF=9B=20Request=20=E8=8E=B7?= =?UTF-8?q?=E5=8F=96=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Controllers/Api/WorkOrderController.php | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/app/Http/Controllers/Api/WorkOrderController.php b/app/Http/Controllers/Api/WorkOrderController.php index 8b49591..bfbdadf 100644 --- a/app/Http/Controllers/Api/WorkOrderController.php +++ b/app/Http/Controllers/Api/WorkOrderController.php @@ -29,20 +29,16 @@ public function store(Request $request) 'host_id' => 'nullable|sometimes|exists:hosts,id', ]); - // 这里无法直接调用,得先转换成 Array - - $request_data = $request->toArray(); - // module_id 和 host_id 必须有个要填写 - if (isset($request_data['module_id']) && isset($request_data['host_id'])) { + if (isset($request->module_id) && isset($request->host_id)) { return $this->error('module_id 和 host_id 至少要填写一个'); } $workOrder = WorkOrder::create([ - 'title' => $request_data['title'], - 'content' => $request_data['content'], - 'module_id' => $request_data['module_id'] ?? null, - 'host_id' => $request_data['host_id'] ?? null, + 'title' => $request->title, + 'content' => $request->input('content'), + 'module_id' => $request->module_id, + 'host_id' => $request->host_id, 'status' => 'pending', ]);