MammutAlex / polyglot by MammutCris

Translate model column in laravel
1,926
2
2
Package Data
Maintainer Username: MammutCris
Maintainer Contact: mammutcris@gmail.com (MammutCris)
Package Create Date: 2017-02-07
Package Last Update: 2018-09-20
Language: PHP
License: MIT
Last Refreshed: 2024-04-16 15:03:04
Package Statistics
Total Downloads: 1,926
Monthly Downloads: 0
Daily Downloads: 0
Total Stars: 2
Total Watchers: 2
Total Forks: 0
Total Open Issues: 0

Polyglot

Build Status Total Downloads Latest Stable Version License Code Climate StyleCI

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