Skip to content

Instantly share code, notes, and snippets.

@endihunter
Created July 3, 2017 10:47
Show Gist options
  • Save endihunter/bf9ea0f8a8855d270a4ba161850373e2 to your computer and use it in GitHub Desktop.
Save endihunter/bf9ea0f8a8855d270a4ba161850373e2 to your computer and use it in GitHub Desktop.
translatable + stapler conflict
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)) {
return $this->getTranslatedAttribute($key);
} 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