public function scopeUpdateSource($query, $datasetId, $newDatasourceId) { if (!empty($newDatasourceId)) { $dataset = Dataset::find($datasetId); //is it event necessary to update source? if ($dataset->fk_dsr_id != $newDatasourceId) { //get all variables $variables = $dataset->variables; foreach ($variables as $variable) { Variable::updateSource($variable->id, $newDatasourceId); } } } }
/** * Update the specified resource in storage. * * @param int $id * @return Response */ public function update(Variable $variable, Request $request) { $input = array_except($request->all(), ['_method', '_token']); //need to update data value sources? if ($request->has("fk_dsr_id")) { Variable::updateSource($variable->id, $request->get("fk_dsr_id")); } $variable->update($input); Cache::flush(); return redirect()->route('variables.show', $variable->id)->with('message', 'Variable updated.'); }