app/Http/Controllers/UserController.php
/**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
Update the specified resource in storage.
Update the specified resource in storage .
public function update(Request $request, $id)
    {
       $respuesta=[];
                    try
                    {
                    $vl=$this->validatorUpdateUsuario($request->all());
                         if ($vl->fails())
                            {
                               return response([
                                   'status' => Response::HTTP_BAD_REQUEST,
                                   'response_time' => microtime(true) - LARAVEL_START,
                                   'error' => "usuario_no_encontrado",
                                   'obj'=>$vl->errors(),
                                   'msg' =>"Campos invalidos",
                                   'request' => $request->all()
                               ],Response::HTTP_BAD_REQUEST);
                            }else
                                {
                                $user=  User::findOrFail($id);
                                $userpass=$user->password;
                                $user->fill($request->all());
                                if ($request->has('password') && !is_null($request->password)) {
                                  $user->password=bcrypt($request->password);
                                }
                                $user->save();
                               return response([
                                     'status' => Response::HTTP_OK,
                                     'response_time' => microtime(true) - LARAVEL_START,
                                     'msg' => 'Editado con exito',
                                     'request' => $request->all()
                                 ],Response::HTTP_OK);
                             }
                    }catch(Exception $e){
                       return response([
                           'status' => Response::HTTP_BAD_REQUEST,
                           'response_time' => microtime(true) - LARAVEL_START,
                           'error' => "usuario_no_encontrado",
                           'consola' =>$e->getMessage(),
                           'msg' =>"Usuario no encontrado",
                           'request' => $request->all()
                       ],Response::HTTP_BAD_REQUEST);
                   }
    }
public function update ( Request $ request , $ id ) { $ respuesta = [ ] ; try { $ vl = $ this -> validatorUpdateUsuario ( $ request -> all ( ) ) ; if ( $ vl -> fails ( ) ) { return response ( [ 'status' => Response :: HTTP_BAD_REQUEST , 'response_time' => microtime ( true ) - LARAVEL_START , 'error' => " usuario_no_encontrado " , 'obj' => $ vl -> errors ( ) , 'msg' => " Campos invalidos " , 'request' => $ request -> all ( ) ] , Response :: HTTP_BAD_REQUEST ) ; } else { $ user = User :: findOrFail ( $ id ) ; $ userpass = $ user -> password ; $ user -> fill ( $ request -> all ( ) ) ; if ( $ request -> has ( 'password' ) && ! is_null ( $ request -> password ) ) { $ user -> password = bcrypt ( $ request -> password ) ; } $ user -> save ( ) ; return response ( [ 'status' => Response :: HTTP_OK , 'response_time' => microtime ( true ) - LARAVEL_START , 'msg' => 'Editado con exito' , 'request' => $ request -> all ( ) ] , Response :: HTTP_OK ) ; } } catch ( Exception $ e ) { return response ( [ 'status' => Response :: HTTP_BAD_REQUEST , 'response_time' => microtime ( true ) - LARAVEL_START , 'error' => " usuario_no_encontrado " , 'consola' => $ e -> getMessage ( ) , 'msg' => " Usuario no encontrado " , 'request' => $ request -> all ( ) ] , Response :: HTTP_BAD_REQUEST ) ; } }
Update the specified resource in storage.
Update the specified resource in storage .
//Validaciòn de las entradas por el metodo POST //return response()->json($vl->errors()); //Busca el usuario en la BD // Si la data es valida se la asignamos al usuario //Encriptamos la contraeña // Guardamos el usuario