I made a similar but more universal
Schema::create('index', function(Blueprint $table) { $table->increments('id'); $table->string('title_uk'); $table->string('title_ru'); $table->string('title_en'); $table->string('heading_uk'); $table->string('heading_ru'); $table->string('heading_en'); $table->string('photo'); $table->timestamps(); });
Model
public function TextTrans($text) { $locale=App::getLocale(); $column=$text.'_'.$locale; return $this->{$column}; }
Now I do not write out a specific function for each language version, as well as for each field, and call it all:
$text=Index::find('1'); $text->TextTrans('title'); $text->TextTrans('heading');
source share