src/ApiResponse.php
public function setData($data = null)
    {
        if ($data instanceof Model) {
            $data = [snake_case(class_basename($data)) => $this->convertObjectToArray($data)];
        } elseif (is_object($data)) {
            $data = $this->convertObjectToArray($data);
        } elseif (is_null($data)) {
            $data = [];
        } elseif (is_string($data)) {
            $data = [static::messageKey() => $data];
        }

        if (! is_array($data)) {
            $data = [static::messageKey() => json_encode($data)];
        }

        if (! array_key_exists(static::codeKey(), $data)) {
            $data[static::codeKey()] = $this->getCode();
        }

        if (! is_null($this->cleanKeys)) {
            $data = $this->cleanArray($data, $this->cleanKeys);
        }

        return parent::setData($data);
    }
public function setData($data = null)
    {
        if ($data instanceof Model) {
            $data = [snake_case(class_basename($data)) => $this->convertObjectToArray($data)];
        } elseif (is_object($data)) {
            $data = $this->convertObjectToArray($data);
        } elseif (is_null($data)) {
            $data = [];
        } elseif (is_string($data)) {
            $data = [static::messageKey() => $data];
        }

        if (! is_array($data)) {
            $data = [static::messageKey() => json_encode($data)];
        }

        if (! array_key_exists(static::codeKey(), $data)) {
            $data[static::codeKey()] = $this->getCode();
        }

        if (! is_null($this->cleanKeys)) {
            $data = $this->cleanArray($data, $this->cleanKeys);
        }

        return parent::setData($data);
    }
Sets the data to be sent as JSON.

@param  mixed  $data
@return $this