Skip to content

Instantly share code, notes, and snippets.

@sajt
Last active April 26, 2022 09:24
Show Gist options
  • Save sajt/0459484d339f06faa49ee93a23dbd205 to your computer and use it in GitHub Desktop.
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.
<?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