app/Http/Controllers/UserController.php
/**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
Store a newly created resource in storage.
Store a newly created resource in storage .
public function store(Request $request)
    {
     $respuesta=[];
        $vl=$this->validarCamposUsuario($request->all());
      if ($vl->fails())
         {
                return response([
                'status' => Response::HTTP_BAD_REQUEST,
                'response_time' => microtime(true) - LARAVEL_START,
                'msg' => 'Error al crear el usuario',
                'error' => 'ERR_01',
                'obj' =>$vl->errors()
                ],Response::HTTP_BAD_REQUEST);
         }else
             {
                $user=new User;
                $user->fill($request->all());
                $user->password=bcrypt($request->password);
                try
                {
                    $user->remember_token = str_random(60);
                    $user->api_token=str_random(60);
                    $user->save();
                    $user->attachRole($request->roles_id);
                      return response([
                            'status' => Response::HTTP_OK,
                            'response_time' => microtime(true) - LARAVEL_START,
                            'usuario' => $user,
                            'msg' => 'Usuario creado con éxito',
                            'request' => $request->all()
                        ],Response::HTTP_OK);
                }catch(Exception $e){
                    return response([
                        'status' => Response::HTTP_BAD_REQUEST,
                        'response_time' => microtime(true) - LARAVEL_START,
                        'error' => 'fallo_el_registro',
                        'consola' =>$e,
                        'request' => $request->all()
                    ],Response::HTTP_BAD_REQUEST);
               }
         }
    }
public function store ( Request $ request ) { $ respuesta = [ ] ; $ vl = $ this -> validarCamposUsuario ( $ request -> all ( ) ) ; if ( $ vl -> fails ( ) ) { return response ( [ 'status' => Response :: HTTP_BAD_REQUEST , 'response_time' => microtime ( true ) - LARAVEL_START , 'msg' => 'Error al crear el usuario' , 'error' => 'ERR_01' , 'obj' => $ vl -> errors ( ) ] , Response :: HTTP_BAD_REQUEST ) ; } else { $ user = new User ; $ user -> fill ( $ request -> all ( ) ) ; $ user -> password = bcrypt ( $ request -> password ) ; try { $ user -> remember_token = str_random ( 60 ) ; $ user -> api_token = str_random ( 60 ) ; $ user -> save ( ) ; $ user -> attachRole ( $ request -> roles_id ) ; return response ( [ 'status' => Response :: HTTP_OK , 'response_time' => microtime ( true ) - LARAVEL_START , 'usuario' => $ user , 'msg' => 'Usuario creado con éxito', 'request' => $ request -> all ( ) ] , Response :: HTTP_OK ) ; } catch ( Exception $ e ) { return response ( [ 'status' => Response :: HTTP_BAD_REQUEST , 'response_time' => microtime ( true ) - LARAVEL_START , 'error' => 'fallo_el_registro' , 'consola' => $ e , 'request' => $ request -> all ( ) ] , Response :: HTTP_BAD_REQUEST ) ; } } }
Store a newly created resource in storage.
Store a newly created resource in storage .
//Validaciòn de las entradas por el metodo POST // return  response()->json( $vl->errors(),Response::HTTP_BAD_REQUEST); //Se encripta la contraseña del usuario.