public function update($id) { try { $registro = Departamentos::find($id); if ($registro) { DB::beginTransaction(); $registro->idpais = Input::get('idpais', $registro->idpais); $registro->nombre = Input::get('nombre', $registro->nombre); if ($registro->save()) { DB::commit(); $registro->pais; $respuesta['registros'] = $registro->toArray(); $respuesta['mensaje'] = 'Registro actualizado exitosamente'; $respuesta['resultado'] = true; return $respuesta; } else { DB::rollback(); $respuesta['registros'] = array(); $respuesta['mensaje'] = 'Error al actualizar registro'; $respuesta['resultado'] = false; return $respuesta; } } else { $respuesta['registros'] = array(); $respuesta['mensaje'] = 'El registro no existe'; $respuesta['resultado'] = false; return $respuesta; } } catch (\Exception $e) { $respuesta['registros'] = array(); $respuesta['mensaje'] = 'Error general: ' . $e; $respuesta['resultado'] = false; return $respuesta; } }
public function delete($id_departamento) { $departamento = Departamentos::find($id_departamento); $departamento->delete(); return response()->json(['success' => true, 'id' => $id_departamento]); }
/** * Remove the specified resource from storage. * * @param int $id * @return Response */ public function destroy($id) { $departamento = \App\Departamentos::find($id); $departamento->delete(); return redirect('departamentos')->with('message', 'Borrado'); }