Skip to content
This repository was archived by the owner on Jun 18, 2019. It is now read-only.
This repository was archived by the owner on Jun 18, 2019. It is now read-only.

Attribute fallback does not work with toArray #448

@rtyshyk

Description

@rtyshyk

Hi,

Looks like I found an issue, the propertyFallback does not work, when toArray is calling.

I guess should be like this (to call \Dimsav\Translatable\Translatable::getAttributeOrFallback)

    /**
     * @return array
     */
    public function toArray()
    {
        $attributes = parent::toArray();

        if ($this->relationLoaded('translations') || $this->toArrayAlwaysLoadsTranslations()) {
            // continue
        } else {
            return $attributes;
        }

        $hiddenAttributes = $this->getHidden();

        foreach ($this->translatedAttributes as $field) {
            if (in_array($field, $hiddenAttributes)) {
                continue;
            }

            if ($translations = $this->getTranslation()) {
-                $attributes[$field] = $translations->$field;
+                $attributes[$field] = $this->$field;
            }
        }

        return $attributes;
    }

am i Right?

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions