namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use RpWebDevelopment\LaravelUgcTranslate\Traits\HasTranslatable;
class Posts extends Model
{
use HasTranslatable;
protected $guarded = [];
}
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use RpWebDevelopment\LaravelUgcTranslate\Traits\HasTranslatable;
class Posts extends Model
{
use HasTranslatable;
public array $ugcTranslatable = [
'title',
'body',
];
protected $guarded = [];
}
$post = App\Models\Post::find(1);
app()->setLocale('en_GB');
echo $post->title;
// outputs "This is a title"
app()->setLocale('it');
echo $post->title;
// outputs "Questo è un titolo"
app()->setLocale('fr');
echo $post->title;
// outputs "Il s'agit d'un titre"
$post = App\Models\Post::find(1);
app()->setLocale('en_GB');
echo $post->title;
// outputs "This is a title"
echo $post->localeField('title', 'it');
// outputs "Questo è un titolo"
echo $post->localeField('title', 'fr');
// outputs "Il s'agit d'un titre"
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use RpWebDevelopment\LaravelUgcTranslate\Traits\HasTranslatable;
class Posts extends Model
{
use HasTranslatable;
protected $guarded = [];
public function getUgcLanguagesAttribute(): array
{
return ['en_GB', 'it'];
}
}