Scopes

translatedIn(?string $locale = null)

Returns all posts being translated in english
1
Post::translatedIn('en')->get();
Copied!

notTranslatedIn(?string $locale = null)

Returns all posts not being translated in english
1
Post::notTranslatedIn('en')->get();
Copied!

translated()

Returns all posts not being translated in any locale
1
Post::translated()->get();
Copied!

withTranslation()

Eager loads translation relationship only for the default and fallback (if enabled) locale
1
Post::withTranslation()->get();
Copied!

listTranslations(string $translationField)

Returns an array containing pairs of post ids and the translated title attribute
1
Post::listsTranslations('title')->get()->toArray();
Copied!
1
[
2
['id' => 1, 'title' => 'My first post'],
3
['id' => 2, 'title' => 'My second post']
4
]
Copied!

where translation

Filters posts by checking the translation against the given value

whereTranslation(string $translationField, $value, ?string $locale = null)

1
Post::whereTranslation('title', 'My first post')->first();
Copied!

orWhereTranslation(string $translationField, $value, ?string $locale = null)

1
Post::whereTranslation('title', 'My first post')
2
->orWhereTranslation('title', 'My second post')
3
->get();
Copied!

whereTranslationLike(string $translationField, $value, ?string $locale = null)

1
Post::whereTranslationLike('title', '%first%')->first();
Copied!

orWhereTranslationLike(string $translationField, $value, ?string $locale = null)

1
Post::whereTranslationLike('title', '%first%')
2
->orWhereTranslationLike('title', '%second%')
3
->get();
Copied!

orderByTranslation(string $translationField, string $sortMethod = 'asc')

Sorts the model by a given translation column value
1
Post::orderByTranslation('title')->get()
Copied!
Last modified 2yr ago