Last active
April 26, 2022 09:24
-
-
Save sajt/0459484d339f06faa49ee93a23dbd205 to your computer and use it in GitHub Desktop.
Revisions
-
sajt revised this gist
Apr 26, 2022 . 1 changed file with 8 additions and 17 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,21 +1,12 @@ <?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); } -
sajt revised this gist
Apr 25, 2022 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -9,7 +9,7 @@ public function __get($key) { $columns = Schema::getColumnListing($this->getTable()); $translatable = []; foreach ($columns as $column) { if (str_ends_with($column, '_en')) { $translatable[] = substr($column, 0, -3); } } -
sajt revised this gist
Apr 25, 2022 . No changes.There are no files selected for viewing
-
sajt created this gist
Apr 25, 2022 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,21 @@ <?php namespace App\Traits; use Illuminate\Support\Facades\Schema; trait TranslationTrait { public function __get($key) { $columns = Schema::getColumnListing($this->getTable()); $translatable = []; foreach ($columns as $column) { if (str_ends_with('_en', $column)) { $translatable[] = substr($column, 0, -3); } } if (in_array($key, $translatable)) { return $this->{$key.'_'.app()->getLocale()}; } return parent::__get($key); } }