protected function intoResource($payload)
    {
        // Transformer are intended to singular resources,
        // so what to do with collections
        if ($this->transformer != null) {
            $payload = $this->transformPayload($payload);
        }

        if($payload instanceof Collection || $payload instanceof AbstractPaginator) {
            return is_array($payload->first()) 
                ?  new ResourceCollection($payload->map(function($item) {
                    return new ArrayWrapper($item);
                }))
                : new ResourceCollection($payload);
        }

        if($payload instanceof Arrayable) {
            return $this->instantiateJsonResource($payload);
        }
        
        if(is_array($payload)) {
            return $this->instantiateJsonResource(new ArrayWrapper($payload));
        }
        
        if($payload instanceof \JsonSerializable) {
            return $this->instantiateJsonResource($payload);
        }

        throw new ResponderException("Cannot serialize object");
    }
protected function intoResource($payload)
    {
        // Transformer are intended to singular resources,
        // so what to do with collections
        if ($this->transformer != null) {
            $payload = $this->transformPayload($payload);
        }

        if($payload instanceof Collection || $payload instanceof AbstractPaginator) {
            return is_array($payload->first()) 
                ?  new ResourceCollection($payload->map(function($item) {
                    return new ArrayWrapper($item);
                }))
                : new ResourceCollection($payload);
        }

        if($payload instanceof Arrayable) {
            return $this->instantiateJsonResource($payload);
        }
        
        if(is_array($payload)) {
            return $this->instantiateJsonResource(new ArrayWrapper($payload));
        }
        
        if($payload instanceof \JsonSerializable) {
            return $this->instantiateJsonResource($payload);
        }

        throw new ResponderException("Cannot serialize object");
    }
protected function intoResource ( $ payload ) { // Transformer are intended to singular resources, // so what to do with collections if ( $ this -> transformer != null ) { $ payload = $ this -> transformPayload ( $ payload ) ; } if ( $ payload instanceof Collection || $ payload instanceof AbstractPaginator ) { return is_array ( $ payload -> first ( ) ) ? new ResourceCollection ( $ payload -> map ( function ( $ item ) { return new ArrayWrapper ( $ item ) ; } ) ) : new ResourceCollection ( $ payload ) ; } if ( $ payload instanceof Arrayable ) { return $ this -> instantiateJsonResource ( $ payload ) ; } if ( is_array ( $ payload ) ) { return $ this -> instantiateJsonResource ( new ArrayWrapper ( $ payload ) ) ; } if ( $ payload instanceof \ JsonSerializable ) { return $ this -> instantiateJsonResource ( $ payload ) ; } throw new ResponderException ( "Cannot serialize object" ) ; }
Use any available transformation method to process
the payload returned by the handler.

@param mixed $payload
@return JsonResource
@throws ResponderException
Use any available transformation method to process the payload returned by the handler .