staudenmeir/eloquent-json-relations

Laravel Translatable

Closed this issue · 1 comments

Problem: We cannot use this package with Laravel Translatable
Error: Trait method getAttributeValue has not been applied, because there are collisions with other trait methods on App\\Product",

It would be nice to be able to use both in a model.

You can combine the packages like this:

class Product extends Model
{
    use HasJsonRelationships, HasTranslations {
        HasJsonRelationships::getAttributeValue as getAttributeValueJson;
        HasTranslations::getAttributeValue as getAttributeValueTranslations;
    }

    public function getAttributeValue($key)
    {
        if (! $this->isTranslatableAttribute($key)) {
            return $this->getAttributeValueJson($key);
        }

        return $this->getAttributeValueTranslations($key);
    }
}