dingo / api

A RESTful API package for the Laravel and Lumen frameworks.
BSD 3-Clause "New" or "Revised" License
9.32k stars 1.25k forks source link

Dingo response is encoding eloquent model three times #1063

Open thaonx opened 8 years ago

thaonx commented 8 years ago

https://github.com/dingo/api/blob/master/src/Http/Response.php#L174

    /**
     * {@inheritdoc}
     */
    public function setContent($content)
    {
        try {
            return parent::setContent($content);
        } catch (UnexpectedValueException $exception) {
            $this->original = $content;
            return $this;
        }
    }

https://github.com/dingo/api/blob/master/src/Http/Response.php#L80

public static function makeFromExisting(IlluminateResponse $old)
    {
        $new = static::create($old->getOriginalContent(), $old->getStatusCode());
        $new->headers = $old->headers;
        return $new;
    }

https://github.com/dingo/api/blob/master/src/Http/Response.php#L112

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

If $content is a eloquent model instance, it will be encoded twice before it be overridden by transformer. Three times encoding for for each response, It is a big problem, right ?

specialtactics commented 4 years ago

Hey @thaonx can you please issue the issue template and provide more details - especially about relevant versions of Laravel, dingo and php ?