PHP code example of paschal-customize-tracy / eloquent-translate

1. Go to this page and download the library: Download paschal-customize-tracy/eloquent-translate library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

paschal-customize-tracy / eloquent-translate example snippets


TracyTran\EloquentTranslate\Providers\TranslateServiceProvider::class,

php artisan vendor:publish --provider="TracyTran\EloquentTranslate\Providers\TranslateServiceProvider"

$app->register(TracyTran\EloquentTranslate\Providers\TranslateServiceProvider::class);

$app->configure('eloquent-translate');



namespace App;

use Illuminate\Database\Eloquent\Model;
use TracyTran\EloquentTranslate\Traits\TranslatorTrait;

class Post extends Model
{
    public $translateAttributes = [

        'title',
        'content'
    ];
}



namespace App;

use Kodeine\Metable\Metable;

use Illuminate\Database\Eloquent\Model;
use TracyTran\EloquentTranslate\Traits\TranslatorTrait;

class Category extends Model{

    use Metable, TranslatorTrait {

        Metable::getAttribute as getMetableAttribute;
        TranslatorTrait::getAttribute as getTranslationAttribute;
    }

    public $translateAttributes = [

        'name',
        'caption'
    ];

    public function getAttribute($key) {

        $attr = $this->getMetableAttribute($key); //Fetch other library's attribute

        $attr = $this->getTranslationAttribute( $key , $attr ); //Call our translation method and pass the last attribute resolved in the second parameter

        return $attr;
    }
}

public function setTranslation($attribute, $locale, $translation, $force = false)

$model->setTranslation('name', 'fr', 'Bonjour')

public function setTranslations($attribute, $translations)

$model = App\Post::find(1);

$translations = [

    'fr' => 'Bonjour',
    'ig' => 'ụtụtụ ọma',
    'yo' => 'e kaaro'
];

$model->setTranslations('name', $translations);