/** * 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"); }
public function excluir($id) { if (!($registro = $this->findById($id))) { throw new RegistroNaoEncontradoException($id); } $Objetivo = new Objetivo(); if ($objetivos = $Objetivo->find("all", array("conditions" => array("Objetivo.objetivo_id" => $id, "Objetivo.status" => 1)))) { throw new Exception("Este Objetico não pode ser excluído pois existem outros objetivos associados ao este."); } $this->id = $id; if ($this->saveField("status", 0)) { return true; } return false; }
/** * Show the form for editing the specified */ public function edit($id) { $this->data['beneficiariosActive'] = 'active'; $this->data['destinos'] = Destino::lists('destino', 'id'); $this->data['beneficiario'] = Beneficiario::where('beneficiarioID', '=', $id)->get()->first(); $this->data['objetivo'] = Objetivo::find($this->data['beneficiario']->objetivo); $this->data['responsable'] = Personal::where('beneficiarioID', '=', $id)->where('tipoPersonal', '=', 'responsable')->get()->first(); $doc = []; // dd($this->data['responsable']); foreach ($this->data['beneficiario']->getDocuments as $documents) { $doc[$documents->type] = $documents->fileName; } $this->data['documents'] = $doc; $this->data['zonificacion'] = Zonificacion::where('beneficiarioID', '=', $id)->get()->first(); // dd($this->data['responsable'] ); //return $this->data; return View::make('admin.beneficiarios.edit', $this->data); }