public function unengineer(Request $request) { $input = $request->all(); $messages = array('oename.required' => '请填写旧工程师姓名!', 'omobile.required' => '请填写旧工程师手机号!', 'nename.required' => '请填写新工程师姓名!', 'nmobile.required' => '请填写新工程师手机号!'); $validator = $this->getValidationFactory()->make($input, ['oename' => 'required', 'omobile' => 'required', 'nename' => 'required', 'nmobile' => 'required'], $messages); if ($validator->fails()) { $messages = $validator->messages(); return $messages; } $oename = $request->oename; $omobile = $request->omobile; $nename = $request->nename; $nmobile = $request->nmobile; $engineerDevice = EngineerDevice::nameMobile($oename, $omobile)->get(); if (empty($engineerDevice->items)) { return response()->json(['msg' => '工程师不存在!']); } EngineerDevice::nameMobile($oename, $omobile)->update(['engineer_name' => $nename, 'mobile' => $nmobile]); echo 1; }
/** * @param $query * @param $sn * @return mixed */ public function scopeSn($query, $sn) { if (!empty($sn)) { //return $query->where('Identifier','like','%'.$identifier.'%'); $engineerDevices = EngineerDevice::sn($sn); if ($engineerDevices) { $ids = array(); foreach ($engineerDevices as $engineerDevice) { $ids[] = $engineerDevice->identifier; } if ($ids) { return $query->whereIn('Identifier', $ids); } } } return $query; }
public function scopeEngineer($query, $engineer) { if (!empty($engineer)) { $engineers = Engineer::name($engineer); if ($engineers) { $ids = array(); foreach ($engineers as $engineer) { $ids[] = $engineer->id; } $eds = EngineerDevice::eids($ids); if ($eds) { $eids = array(); foreach ($eds as $ed) { $eids[] = $ed->identifier; } return $query->whereIn('Identifier', $eids); } } } return $query; }