public function agregar()
 {
     $respuesta = Direccion::agregar(Input::all());
     if ($respuesta['error'] == true) {
         return Redirect::to('/')->withErrors($respuesta['mensaje'])->withInput();
     } else {
         return Redirect::to('/')->with('mensaje', $respuesta['mensaje']);
     }
 }
Exemplo n.º 2
0
 public static function agregar($input)
 {
     $respuesta = array();
     $reglas = array('email' => array('required', 'email'));
     $validator = Validator::make($input, $reglas);
     if ($validator->fails()) {
         $respuesta['mensaje'] = $validator->messages()->first('email');
         $respuesta['error'] = true;
     } else {
         $datos = array('email' => $input['email'], 'estado' => 'A', 'fecha_carga' => date("Y-m-d H:i:s"), 'usuario_id_carga' => '1');
         if (isset($input['apellido']) && $input['apellido'] != "") {
             $datos['apellido'] = $input['apellido'];
         }
         if (isset($input['nombre']) && $input['nombre'] != "") {
             $datos['nombre'] = $input['nombre'];
         }
         if (isset($input['fecha_nacimiento']) && $input['fecha_nacimiento'] != "") {
             $datos['fecha_nacimiento'] = $input['fecha_nacimiento'];
         }
         if (isset($input['calle']) && $input['calle'] != "") {
             $direccion = Direccion::agregar($input);
             if (!$direccion['error']) {
                 $datos['direccion_id'] = $direccion['data']->id;
             }
         }
         $persona = static::create($datos);
         if (isset($input['telefono']) && $input['telefono'] != "") {
             $telefono = Telefono::agregar($input);
             if (!$telefono['error']) {
                 $info = array('estado' => 'A');
                 $persona->telefonos()->attach($telefono['data'], $info);
             }
         }
         $respuesta['mensaje'] = 'Persona creada.';
         $respuesta['error'] = false;
         $respuesta['data'] = $persona;
     }
     return $respuesta;
 }