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)