Skip to content

Instantly share code, notes, and snippets.

@endihunter
Created April 11, 2017 08:22
Show Gist options
  • Save endihunter/ab1c83f5108465c5cf71ff810629007b to your computer and use it in GitHub Desktop.
Save endihunter/ab1c83f5108465c5cf71ff810629007b to your computer and use it in GitHub Desktop.
Workaround to fix translatable & staplerable methods collision.
<?php
class SomeClass {
use HasTranslations, EloquentTrait {
HasTranslations::getAttribute as getTranslatedAttribute;
HasTranslations::setAttribute as setTranslatedAttribute;
EloquentTrait::getAttribute as getStaplerableAttribute;
EloquentTrait::setAttribute as setStaplerableAttribute;
}
public function getAttribute($key)
{
if ($this->isKeyReturningTranslationText($key)) {
if (!$translate = $this->getTranslatedAttribute($key)) {
$translate = $this->translate(\localizer\getDefault()->id());
$translate = $translate->$key;
}
return $translate;
} else {
if (array_key_exists($key, $this->attachedFiles)) {
return $this->getStaplerableAttribute($key);
}
}
return parent::getAttribute($key);
}
public function setAttribute($key, $value)
{
if ($this->hasTranslatedAttributes() && in_array($key, $this->translatedAttributes)) {
return $this->setTranslatedAttribute($key, $value);
} else {
if (array_key_exists($key, $this->attachedFiles)) {
return $this->setStaplerableAttribute($key, $value);
}
}
return parent::setAttribute($key, $value);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment