PHP code example of paschaldev / eloquent-translate
1. Go to this page and download the library: Download paschaldev/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/ */
namespace App;
use Illuminate\Database\Eloquent\Model;
use PaschalDev\EloquentTranslate\Traits\TranslatorTrait;
class Post extends Model
{
public $translateAttributes = [
'title',
'content'
];
}
namespace App;
use Kodeine\Metable\Metable;
use Illuminate\Database\Eloquent\Model;
use PaschalDev\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)