使 Eloquent 模型可翻译
This package contains a trait HasTranslations to make Eloquent models translatable. Translations are stored as json. There is no extra table needed to hold them.
use Illuminate\Database\Eloquent\Model;
use Spatie\Translatable\Attributes\Translatable;
use Spatie\Translatable\HasTranslations;
#[Translatable('name', 'description')]
class NewsItem extends Model
{
use HasTranslations;
// ...
}
The attribute accepts a variadic list of column names, so you can pass as many as you need.
Alternatively, you can declare the translatable attributes via a public $translatable property:
use Illuminate\Database\Eloquent\Model;
use Spatie\Translatable\HasTranslations;
class NewsItem extends Model
{
use HasTranslations;
public $translatable = ['name'];
}
When both the property and the attribute are present, their values are merged and deduplicated.
After the trait is applied on the model you can do these things:
…
Also providing scoped queries for retrieving records based on locales
…
We invest a lot of resources into creating best in class open source packages. You can support us by buying one of our paid products.
We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on our contact page. We publish all received postcards on our virtual postcard wall.
All documentation is available on our documentation site.
composer test
Please see CONTRIBUTING for details.
If you've found a bug regarding security please mail [email protected] instead of using the issue tracker.
You're free to use this package, but if it makes it to your production environment we highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using.
Our address is: Spatie, Kruikstraat 22, 2018 Antwerp, Belgium.
We publish all received postcards on our company website.
We got the idea to store translations as json in a column from Mohamed Said. Parts of the readme of his multilingual package were used in this readme.
The MIT License (MIT). Please see License File for more information.
暂无开放 Issues,或尚未同步最近议题。