public function morph($format = 'json')
    {
        $this->content = $this->getOriginalContent();

        $this->fireMorphingEvent();

        if (isset(static::$transformer) && static::$transformer->transformableResponse($this->content)) {
            $this->content = static::$transformer->transform($this->content);
        }

        $formatter = static::getFormatter($format);

        $formatter->setOptions(static::getFormatsOptions($format));

        $defaultContentType = $this->headers->get('Content-Type');

        $this->headers->set('Content-Type', $formatter->getContentType());

        $this->fireMorphedEvent();

        if ($this->content instanceof EloquentModel) {
            $this->content = $formatter->formatEloquentModel($this->content);
        } elseif ($this->content instanceof EloquentCollection) {
            $this->content = $formatter->formatEloquentCollection($this->content);
        } elseif (\is_array($this->content) || $this->content instanceof ArrayObject || $this->content instanceof Arrayable) {
            $this->content = $formatter->formatArray($this->content);
        } else {
            $this->headers->set('Content-Type', $defaultContentType);
        }

        return $this;
    }
public function morph($format = 'json')
    {
        $this->content = $this->getOriginalContent();

        $this->fireMorphingEvent();

        if (isset(static::$transformer) && static::$transformer->transformableResponse($this->content)) {
            $this->content = static::$transformer->transform($this->content);
        }

        $formatter = static::getFormatter($format);

        $formatter->setOptions(static::getFormatsOptions($format));

        $defaultContentType = $this->headers->get('Content-Type');

        $this->headers->set('Content-Type', $formatter->getContentType());

        $this->fireMorphedEvent();

        if ($this->content instanceof EloquentModel) {
            $this->content = $formatter->formatEloquentModel($this->content);
        } elseif ($this->content instanceof EloquentCollection) {
            $this->content = $formatter->formatEloquentCollection($this->content);
        } elseif (\is_array($this->content) || $this->content instanceof ArrayObject || $this->content instanceof Arrayable) {
            $this->content = $formatter->formatArray($this->content);
        } else {
            $this->headers->set('Content-Type', $defaultContentType);
        }

        return $this;
    }
public function morph ( $ format = 'json' ) { $ this -> content = $ this -> getOriginalContent ( ) ; $ this -> fireMorphingEvent ( ) ; if ( isset ( static :: $ transformer ) && static :: $ transformer -> transformableResponse ( $ this -> content ) ) { $ this -> content = static :: $ transformer -> transform ( $ this -> content ) ; } $ formatter = static :: getFormatter ( $ format ) ; $ formatter -> setOptions ( static :: getFormatsOptions ( $ format ) ) ; $ defaultContentType = $ this -> headers -> get ( 'Content-Type' ) ; $ this -> headers -> set ( 'Content-Type' , $ formatter -> getContentType ( ) ) ; $ this -> fireMorphedEvent ( ) ; if ( $ this -> content instanceof EloquentModel ) { $ this -> content = $ formatter -> formatEloquentModel ( $ this -> content ) ; } elseif ( $ this -> content instanceof EloquentCollection ) { $ this -> content = $ formatter -> formatEloquentCollection ( $ this -> content ) ; } elseif ( \ is_array ( $ this -> content ) || $ this -> content instanceof ArrayObject || $ this -> content instanceof Arrayable ) { $ this -> content = $ formatter -> formatArray ( $ this -> content ) ; } else { $ this -> headers -> set ( 'Content-Type' , $ defaultContentType ) ; } return $ this ; }
Morph the API response to the appropriate format.

@param string $format

@return \Dingo\Api\Http\Response
Morph the API response to the appropriate format .