public function add() { $input = Input::only('name', 'manufacturer_id', 'battery_lifetime', 'default_password', 'comment'); $name = $input['name']; $manufacturerId = $input['manufacturer_id']; $batteryLifetime = $input['battery_lifetime']; $defaultPassword = $input['default_password']; $comment = $input['comment']; $validator = Validator::make($input, ['name' => 'required', 'manufacturer_id' => 'required', 'battery_lifetime' => 'required|integer']); if ($validator->fails() or !$this->manufacturerService->isExist($manufacturerId)) { return redirect()->back()->with('error_tips', '提交数据不完整')->withInput(); } $deviceModel = new DeviceModel(); $deviceModel->name = $name; $deviceModel->manufacturer_id = $manufacturerId; $deviceModel->battery_lifetime = $batteryLifetime; $deviceModel->default_password = $defaultPassword; $deviceModel->comment = $comment; $deviceModel->save(); return redirect()->route('deviceModels')->with("success_tips", "保存成功!"); }