Last active
April 26, 2022 09:24
-
-
Save sajt/0459484d339f06faa49ee93a23dbd205 to your computer and use it in GitHub Desktop.
This trait extracts every field from the current model, end make an extra attribute if it is a translatable properities.
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 | |
trait TranslationTrait { | |
public function __get($key) | |
{ | |
if (collect(Schema::getColumnListing($this->getTable()))->contains($column = $key.'_'.app()->getLocale())) | |
{ | |
return $this->{$column}; | |
} | |
return parent::__get($key); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment