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

Attribute fallback does not work with toArray #448

Closed
rtyshyk opened this issue Mar 22, 2018 · 1 comment
Closed

Attribute fallback does not work with toArray #448

rtyshyk opened this issue Mar 22, 2018 · 1 comment

Comments

@rtyshyk
Copy link

rtyshyk commented Mar 22, 2018

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?

@Gummibeer
Copy link
Collaborator

@rtyshyk in general you were right. I've proposed a PR that now uses the getAttributeOrFallback() method.

@Gummibeer Gummibeer added the bug label May 15, 2018
dimsav pushed a commit that referenced this issue Jul 24, 2018
* use fallback in attributesToArray

#448

* fix empty line

* define locale that's not present

* fix getAttributeOrFallback()

* fix php cs
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants