Created
April 11, 2017 08:22
-
-
Save endihunter/ab1c83f5108465c5cf71ff810629007b to your computer and use it in GitHub Desktop.
Workaround to fix translatable & staplerable methods collision.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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