public function updateSource(Variable $variable, $newDatasourceId) { if (!empty($newDatasourceId)) { //is it event necessary to update source? if ($variable->fk_dsr_id != $newDatasourceId) { //it is update both variable source all sources of all variable values $variable->fk_dsr_id = $newDatasourceId; $variable->save(); //update all variable values DataValue::where('fk_var_id', $variable->id)->update(array('fk_dsr_id' => $newDatasourceId)); Cache::flush(); } } }