lib/Http/Controllers/Base/ObjectActions/PatchObjectTrait.php
public function patch(Request $request, Fractal $fractal, InputGateContract $inputGate)
    {
        $this->beforeRequest($request, func_get_args());
        $id = $this->parseObjectId($request);
        $model = $this->loadAuthorizeObject($id, 'update');
        $input = $request->json()->all();
        if (!is_array($input) || empty($input)) {
            throw new UnprocessableEntityHttpException("Invalid request body");
        }
        $attributes = $originalAttributes = array_get($input, 'data.attributes', []);
        $context = app('context');
        foreach ($context as $key => $value) {
            unset($attributes[$key]);
        }
        $relationships = array_get($input, 'data.relationships', []);
        $attributes = $inputGate->process($model, $attributes, 'update');
        $validatedRelationshipData = $this->validateRelationshipData($model, $relationships, 'update');
        // do update logic
        if ($model->update($attributes) && $this->saveRelationshipData($validatedRelationshipData)) {
            return $this->respondWithUpdated(
                $fractal->createData(new FractalItem($this->loadAuthorizeObject($id, 'update'), $this->getTransformer(), $this->getResourceKey()))
            );
        }
        
        throw new ServerErrorHttpException("Unable to save object. Try again later.");
    }
public function patch(Request $request, Fractal $fractal, InputGateContract $inputGate)
    {
        $this->beforeRequest($request, func_get_args());
        $id = $this->parseObjectId($request);
        $model = $this->loadAuthorizeObject($id, 'update');
        $input = $request->json()->all();
        if (!is_array($input) || empty($input)) {
            throw new UnprocessableEntityHttpException("Invalid request body");
        }
        $attributes = $originalAttributes = array_get($input, 'data.attributes', []);
        $context = app('context');
        foreach ($context as $key => $value) {
            unset($attributes[$key]);
        }
        $relationships = array_get($input, 'data.relationships', []);
        $attributes = $inputGate->process($model, $attributes, 'update');
        $validatedRelationshipData = $this->validateRelationshipData($model, $relationships, 'update');
        // do update logic
        if ($model->update($attributes) && $this->saveRelationshipData($validatedRelationshipData)) {
            return $this->respondWithUpdated(
                $fractal->createData(new FractalItem($this->loadAuthorizeObject($id, 'update'), $this->getTransformer(), $this->getResourceKey()))
            );
        }
        
        throw new ServerErrorHttpException("Unable to save object. Try again later.");
    }
public function patch ( Request $ request , Fractal $ fractal , InputGateContract $ inputGate ) { $ this -> beforeRequest ( $ request , func_get_args ( ) ) ; $ id = $ this -> parseObjectId ( $ request ) ; $ model = $ this -> loadAuthorizeObject ( $ id , 'update' ) ; $ input = $ request -> json ( ) -> all ( ) ; if ( ! is_array ( $ input ) || empty ( $ input ) ) { throw new UnprocessableEntityHttpException ( "Invalid request body" ) ; } $ attributes = $ originalAttributes = array_get ( $ input , 'data.attributes' , [ ] ) ; $ context = app ( 'context' ) ; foreach ( $ context as $ key => $ value ) { unset ( $ attributes [ $ key ] ) ; } $ relationships = array_get ( $ input , 'data.relationships' , [ ] ) ; $ attributes = $ inputGate -> process ( $ model , $ attributes , 'update' ) ; $ validatedRelationshipData = $ this -> validateRelationshipData ( $ model , $ relationships , 'update' ) ; // do update logic if ( $ model -> update ( $ attributes ) && $ this -> saveRelationshipData ( $ validatedRelationshipData ) ) { return $ this -> respondWithUpdated ( $ fractal -> createData ( new FractalItem ( $ this -> loadAuthorizeObject ( $ id , 'update' ) , $ this -> getTransformer ( ) , $ this -> getResourceKey ( ) ) ) ) ; } throw new ServerErrorHttpException ( "Unable to save object. Try again later." ) ; }
Update the object

@param  Request  $request Request object
@param  string $id Unique identifier for the object
@return ResponseInterface    Response for object
Update the object