/** * Update the specified department in storage. */ public function update($id) { $dest = Destino::findOrFail($id); $validator = Validator::make($input = Input::all(), Destino::rules($id)); if ($validator->fails()) { return Redirect::back()->withErrors($validator)->withInput(); } $dest->update(['destino' => $input['destino']]); foreach ($input['objetivo'] as $index => $value) { if ($value == '' && !isset($input['objID'][$index])) { continue; } if (isset($input['objID'][$index])) { if ($value == '') { Objetivo::destroy($input['objID'][$index]); } else { $obj = Objetivo::find($input['objID'][$index]); $obj->objetivo = $value; $obj->save(); } } else { Objetivo::firstOrCreate(['destID' => $dest->id, 'objetivo' => $value]); } } return Redirect::route('admin.destinos.index')->with('success', "<strong>{$input['destino']}</strong> Actualizado correctamente"); }