app/Http/Controllers/ClienteController.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)
    {
        try {
            $vl=$this->validatorCrearCliente($request->all());
            if ($vl->fails()){
                return response([
                    'status' => Response::HTTP_BAD_REQUEST,
                    'response_time' => microtime(true) - LARAVEL_START,
                    'msg' => 'Error al actualizar el cliente',
                    'error' => 'ERR_02',
                    'obj' =>$vl->errors()
                ],Response::HTTP_BAD_REQUEST);
            }else{
                $cliente=  Cliente::findOrFail($id);
                $historico_cliente = new Historico_cliente;
                $cliente->fill($request->all());
                $historico_cliente->fill($request->all());
                $cliente->save();
                $historico_cliente->cliente_id = $cliente->id;
                $historico_cliente->save();
                return response([
                        'status' => Response::HTTP_OK,
                        'response_time' => microtime(true) - LARAVEL_START,
                        'obj' => $cliente,
                        'error' => null,
                        'msg' => 'Cliente actualizado con éxito',
                    ],Response::HTTP_OK);
            }
        }catch(Exception $e){
            return response([
                'status' => Response::HTTP_BAD_REQUEST,
                'response_time' => microtime(true) - LARAVEL_START,
                'error' => 'ERR_04',
                'msg' => 'excepcion, fallo la petición',
                'consola' =>$e->getMessage(),
                'obj' => $request->all()
                ],Response::HTTP_BAD_REQUEST);
        }
    }
public function update ( Request $ request , $ id ) { try { $ vl = $ this -> validatorCrearCliente ( $ request -> all ( ) ) ; if ( $ vl -> fails ( ) ) { return response ( [ 'status' => Response :: HTTP_BAD_REQUEST , 'response_time' => microtime ( true ) - LARAVEL_START , 'msg' => 'Error al actualizar el cliente' , 'error' => 'ERR_02' , 'obj' => $ vl -> errors ( ) ] , Response :: HTTP_BAD_REQUEST ) ; } else { $ cliente = Cliente :: findOrFail ( $ id ) ; $ historico_cliente = new Historico_cliente ; $ cliente -> fill ( $ request -> all ( ) ) ; $ historico_cliente -> fill ( $ request -> all ( ) ) ; $ cliente -> save ( ) ; $ historico_cliente -> cliente_id = $ cliente -> id ; $ historico_cliente -> save ( ) ; return response ( [ 'status' => Response :: HTTP_OK , 'response_time' => microtime ( true ) - LARAVEL_START , 'obj' => $ cliente , 'error' => null , 'msg' => 'Cliente actualizado con éxito', ] , Response :: HTTP_OK ) ; } } catch ( Exception $ e ) { return response ( [ 'status' => Response :: HTTP_BAD_REQUEST , 'response_time' => microtime ( true ) - LARAVEL_START , 'error' => 'ERR_04' , 'msg' => 'excepcion, fallo la petición', 'consola' => $ e -> getMessage ( ) , 'obj' => $ 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 //Busca el cliente en la BD // Si la data es valida se la asignamos al cliente // Actualizamos el cliente