Laravel Translator - An Eloquent translator for Laravel!
An easy to use Eloquent translator for Laravel. No configuration or service providers needed.
// Fetch an Eloquent object
$article = Article::find(1);
// Display title in default language
echo $article->title;
// Change the current locale to Swedish
App::setLocale('sv');
// Display title in Swedish
echo $article->title;
![enter image description here][1]
Installation
Require this package, with Composer, in the root directory of your project.
composer require vinkla/translator
Create a new migration for the translations. In our case we want to translate the articles table.
php artisan make:migration create_article_translations_table
Make sure you add the article_id and locale columns. Also, make them unique.
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
/**
* This is the article translations table seeder class.
*
* @author Vincent Klaiber <[email protected]>
*/
class CreateArticleTranslationsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('article_translations', function (Blueprint $table) {
$table->increments('id');
$table->string('title'); // Translated column.
$table->integer('article_id')->unsigned()->index();
$table->foreign('article_id')
->references('id')
->on('articles')
->onDelete('cascade');
$table->string('locale')->index();
$table->unique(['
Link: