mammut-alex / polyglot
Translate model column in laravel
Installs: 1 927
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 2
Forks: 0
Open Issues: 0
Requires
- php: >=5.6.4
Requires (Dev)
- laravel/laravel: dev-develop
- phpunit/phpunit: ^5.7
README
Installation
Require this package in your composer.json
and update composer.
"mammut-alex/polyglot": "0.2.*"
or composer require mammut-alex/polyglot
Documentation
Translator works with a database, it looks for a prefix code language
Here is an example Migration
$table->string('name_en'); $table->string('name_uk'); $table->string('name_ru');
To use polyglot, connect it to your model and use feature for translation.
namespace App; use Illuminate\Database\Eloquent\Model; use MammutAlex\Polyglot\Polyglot; class YouModel extends Model { use Polyglot; public function name() { return $this->translation('name'); } ...
The function will return the translation in the selected language user
An example of the use in blade:
<h1>{{$model->name()}}</h1>
See more example in tests, documentation being developed