PHP Trait Dimsav\Translatable\Translatable

Afficher le fichier Open project: dimsav/laravel-translatable

Méthodes publiques

Méthode Description
__isset ( $key ) : boolean
deleteTranslations ( string | array | null $locales = null ) Deletes all translations for this model.
fill ( array $attributes )
getAttribute ( string $key ) : mixed
getLocaleKey ( ) : string
getNewTranslation ( string $locale ) : Model
getRelationKey ( ) : string
getTranslation ( string | null $locale = null, boolean $withFallback = null ) : Model | null
getTranslationModelName ( ) : string
getTranslationModelNameDefault ( ) : string
hasTranslation ( string | null $locale = null ) : boolean
isTranslationAttribute ( string $key ) : boolean
save ( array $options = [] ) : boolean
scopeListsTranslations ( Builder $query, string $translationField ) Adds scope to get a list of translated attributes, using the current locale.
scopeNotTranslatedIn ( Builder $query, string $locale = null ) : Builder | static
scopeTranslated ( Builder $query ) : Builder | static
scopeTranslatedIn ( Builder $query, string $locale = null ) : Builder | static
scopeWhereTranslation ( Builder $query, string $key, string $value, string $locale = null ) : Builder | static This scope filters results by checking the translation fields.
scopeWhereTranslationLike ( Builder $query, string $key, string $value, string $locale = null ) : Builder | static This scope filters results by checking the translation fields.
scopeWithTranslation ( Builder $query ) This scope eager loads the translations for the default and the fallback locale only.
setAttribute ( string $key, mixed $value )
toArray ( ) : array
translate ( string | null $locale = null, boolean $withFallback = false ) : Model | null Alias for getTranslation().
translateOrDefault ( string $locale ) : Model | null Alias for getTranslation().
translateOrNew ( string $locale ) : Model | null Alias for getTranslationOrNew().
translations ( ) : Illuminate\Database\Eloquent\Relations\HasMany

Méthodes protégées

Méthode Description
getLocaleSeparator ( ) : string
getLocales ( ) : array
getTranslationOrNew ( string $locale ) : Model | null
isKeyALocale ( string $key ) : boolean
isTranslationDirty ( Model $translation ) : boolean
locale ( ) : string
saveTranslations ( ) : boolean

Private Methods

Méthode Description
alwaysFillable ( ) : boolean
getFallbackLocale ( null $locale = null ) : string
getLanguageFromCountryBasedLocale ( $locale ) : string
getTranslationByLocaleKey ( string $key )
getTranslationsTable ( ) : string
isLocaleCountryBased ( $locale ) : boolean
useFallback ( ) : boolean | null

Method Details

__isset() public méthode

public __isset ( $key ) : boolean
$key
Résultat boolean

deleteTranslations() public méthode

Deletes all translations for this model.
public deleteTranslations ( string | array | null $locales = null )
$locales string | array | null The locales to be deleted (array or single string) (e.g., ["en", "de"] would remove these translations).

fill() public méthode

public fill ( array $attributes )
$attributes array

getAttribute() public méthode

public getAttribute ( string $key ) : mixed
$key string
Résultat mixed

getLocaleKey() public méthode

public getLocaleKey ( ) : string
Résultat string

getLocaleSeparator() protected méthode

protected getLocaleSeparator ( ) : string
Résultat string

getLocales() protected méthode

protected getLocales ( ) : array
Résultat array

getNewTranslation() public méthode

public getNewTranslation ( string $locale ) : Model
$locale string
Résultat Illuminate\Database\Eloquent\Model

getRelationKey() public méthode

public getRelationKey ( ) : string
Résultat string

getTranslation() public méthode

public getTranslation ( string | null $locale = null, boolean $withFallback = null ) : Model | null
$locale string | null
$withFallback boolean
Résultat Illuminate\Database\Eloquent\Model | null

getTranslationModelName() public méthode

public getTranslationModelName ( ) : string
Résultat string

getTranslationModelNameDefault() public méthode

getTranslationOrNew() protected méthode

protected getTranslationOrNew ( string $locale ) : Model | null
$locale string
Résultat Illuminate\Database\Eloquent\Model | null

hasTranslation() public méthode

public hasTranslation ( string | null $locale = null ) : boolean
$locale string | null
Résultat boolean

isKeyALocale() protected méthode

protected isKeyALocale ( string $key ) : boolean
$key string
Résultat boolean

isTranslationAttribute() public méthode

public isTranslationAttribute ( string $key ) : boolean
$key string
Résultat boolean

isTranslationDirty() protected méthode

protected isTranslationDirty ( Model $translation ) : boolean
$translation Illuminate\Database\Eloquent\Model
Résultat boolean

locale() protected méthode

protected locale ( ) : string
Résultat string

save() public méthode

public save ( array $options = [] ) : boolean
$options array
Résultat boolean

saveTranslations() protected méthode

protected saveTranslations ( ) : boolean
Résultat boolean

scopeListsTranslations() public méthode

Example usage: Country::listsTranslations('name')->get()->toArray() Will return an array with items: [ 'id' => '1', // The id of country 'name' => 'Griechenland' // The translated name ]
public scopeListsTranslations ( Builder $query, string $translationField )
$query Illuminate\Database\Eloquent\Builder
$translationField string

scopeNotTranslatedIn() public méthode

public scopeNotTranslatedIn ( Builder $query, string $locale = null ) : Builder | static
$query Illuminate\Database\Eloquent\Builder
$locale string
Résultat Illuminate\Database\Eloquent\Builder | static

scopeTranslated() public méthode

public scopeTranslated ( Builder $query ) : Builder | static
$query Illuminate\Database\Eloquent\Builder
Résultat Illuminate\Database\Eloquent\Builder | static

scopeTranslatedIn() public méthode

public scopeTranslatedIn ( Builder $query, string $locale = null ) : Builder | static
$query Illuminate\Database\Eloquent\Builder
$locale string
Résultat Illuminate\Database\Eloquent\Builder | static

scopeWhereTranslation() public méthode

This scope filters results by checking the translation fields.
public scopeWhereTranslation ( Builder $query, string $key, string $value, string $locale = null ) : Builder | static
$query Illuminate\Database\Eloquent\Builder
$key string
$value string
$locale string
Résultat Illuminate\Database\Eloquent\Builder | static

scopeWhereTranslationLike() public méthode

This scope filters results by checking the translation fields.
public scopeWhereTranslationLike ( Builder $query, string $key, string $value, string $locale = null ) : Builder | static
$query Illuminate\Database\Eloquent\Builder
$key string
$value string
$locale string
Résultat Illuminate\Database\Eloquent\Builder | static

scopeWithTranslation() public méthode

We can use this as a shortcut to improve performance in our application.
public scopeWithTranslation ( Builder $query )
$query Illuminate\Database\Eloquent\Builder

setAttribute() public méthode

public setAttribute ( string $key, mixed $value )
$key string
$value mixed

toArray() public méthode

public toArray ( ) : array
Résultat array

translate() public méthode

Alias for getTranslation().
public translate ( string | null $locale = null, boolean $withFallback = false ) : Model | null
$locale string | null
$withFallback boolean
Résultat Illuminate\Database\Eloquent\Model | null

translateOrDefault() public méthode

Alias for getTranslation().
public translateOrDefault ( string $locale ) : Model | null
$locale string
Résultat Illuminate\Database\Eloquent\Model | null

translateOrNew() public méthode

Alias for getTranslationOrNew().
public translateOrNew ( string $locale ) : Model | null
$locale string
Résultat Illuminate\Database\Eloquent\Model | null

translations() public méthode

public translations ( ) : Illuminate\Database\Eloquent\Relations\HasMany
Résultat Illuminate\Database\Eloquent\Relations\HasMany