/** * Return Configurable ID given the name * @param $name the name of the module */ public static function idByName($name = NULL) { if ($name) { if ($name) { try { $conf = Configurable::where('name', $name)->orderBy('name', 'asc')->firstOrFail(); return $conf->id; } catch (ModelNotFoundException $e) { Log::error("The Configurable ` {$name} ` does not exist: " . $e->getMessage()); //TODO: send email? return null; } } } else { return null; } }
/** * @return \Illuminate\Routing\Route|null|string */ public function ingnoreId() { $id = $this->route('configurable'); $name = $this->input('name'); return Configurable::where(compact('id', 'name'))->exists() ? $id : ''; }
/** * Update the specified resource in storage. * * @param int $id * @return Response */ public function update(AnalyserRequest $request, $id) { $analyser = Analyser::find($id); $analyser->name = $request->name; $analyser->version = $request->version; $analyser->test_category_id = $request->test_category_id; $analyser->comm_type = $request->comm_type; $analyser->feed_source = $request->feed_source; $analyser->config_file = $request->config_file; $analyser->description = $request->description; $analyser->user_id = 1; $analyser->save(); //dd(Configurable::idByName($analyser->name)); /* Proceed to update the corresponding equipment */ if (count(Configurable::where('name', $analyser->name)->get()) > 0) { $configurable = Configurable::where('name', $analyser->name)->first(); } else { $configurable = new Configurable(); } $configurable->name = $analyser->name; $configurable->user_id = 1; $configurable->save(); /* Delete existing configs */ DB::table('configurable_fields')->where('configurable_id', '=', $configurable->id)->delete(); /* Save configurable-fields for the configurable RS232,TCP/IP, MSACCESS,HTTP,TEXT */ $fields = []; if ($analyser->feed_source == Analyser::RS232) { $fields = Field::RS232; } else { if ($analyser->feed_source == Analyser::TCPIP) { $fields = Field::TCPIP; } else { if ($analyser->feed_source == Analyser::MSACCESS) { $fields = Field::MSACCESS; } else { if ($analyser->feed_source == Analyser::TEXT) { $fields = Field::TEXT; } } } } foreach ($fields as $field) { $fId = Field::idByName($field); $conf = ConField::where('configurable_id', $configurable->id)->where('field_id', $fId)->first(); if ($conf) { $conField = ConField::find($conf->id); } else { $conField = new ConField(); } $conField->configurable_id = $configurable->id; $conField->field_id = $fId; $conField->user_id = 1; $conField->save(); } $url = session('SOURCE_URL'); return redirect()->to($url)->with('message', trans('terms.record-successfully-saved'))->with('active_analyser', $analyser->id); }