PHP Трейт Eloquence\Behaviours\CamelCasing

Показать файл Открыть проект

Открытые свойства

Свойство Тип Описание
$enforceCamelCase boolean Alter eloquent model behaviour so that model attributes can be accessed via camelCase, but more importantly, attributes also get returned as camelCase fields.

Открытые методы

Метод Описание
__isset ( $key ) : mixed Because we are changing the case of keys and want to use camelCase throughout the application, whenever we do isset checks we need to ensure that we check using snake_case.
__unset ( $key ) : void Because we are changing the case of keys and want to use camelCase throughout the application, whenever we do unset variables we need to ensure that we unset using snake_case.
attributesToArray ( ) : array Return the attributes for the model, converting field casing if necessary.
getAttribute ( string $key ) : mixed Retrieve a given attribute but allow it to be accessed via alternative case methods (such as camelCase).
getAttributes ( $keys = [] ) : array Converts the attributes to a camel-case version, if applicable.
getDates ( ) : array Overloads the eloquent getDates method to ensure that date field declarations can be made in camelCase but mapped to/from DB in snake_case.
getHidden ( ) : array Overloads eloquent's getHidden method to ensure that hidden fields declared in camelCase are actually hidden and not exposed when models are turned into arrays.
getOriginal ( string $key = null, mixed $default = null ) : array Get the model's original attribute values.
getTrueKey ( $key ) : string Retrieves the true key name for a key.
isCamelCase ( ) : boolean Determines whether the model (or its parent) requires camelcasing. This is required for pivot models whereby they actually depend on their parents for this feature.
relationsToArray ( ) : array Get the model's relationships, converting field casing if necessary.
setAttribute ( string $key, mixed $value ) Overloads the eloquent setAttribute method to ensure that fields accessed in any case are converted to snake_case, which is the defacto standard for field names in databases.
toCamelCase ( mixed $attributes ) : array Converts a given array of attribute keys to the casing required by CamelCaseModel.
toSnakeCase ( $attributes ) : array Converts a given array of attribute keys to the casing required by CamelCaseModel.

Защищенные методы

Метод Описание
getSnakeKey ( $key ) : string If the field names need to be converted so that they can be accessed by camelCase, then we can do that here.

Описание методов

__isset() публичный Метод

Because we are changing the case of keys and want to use camelCase throughout the application, whenever we do isset checks we need to ensure that we check using snake_case.
public __isset ( $key ) : mixed
$key
Результат mixed

__unset() публичный Метод

Because we are changing the case of keys and want to use camelCase throughout the application, whenever we do unset variables we need to ensure that we unset using snake_case.
public __unset ( $key ) : void
$key
Результат void

attributesToArray() публичный Метод

Return the attributes for the model, converting field casing if necessary.
public attributesToArray ( ) : array
Результат array

getAttribute() публичный Метод

Retrieve a given attribute but allow it to be accessed via alternative case methods (such as camelCase).
public getAttribute ( string $key ) : mixed
$key string
Результат mixed

getAttributes() публичный Метод

Converts the attributes to a camel-case version, if applicable.
public getAttributes ( $keys = [] ) : array
Результат array

getDates() публичный Метод

Overloads the eloquent getDates method to ensure that date field declarations can be made in camelCase but mapped to/from DB in snake_case.
public getDates ( ) : array
Результат array

getHidden() публичный Метод

Overloads eloquent's getHidden method to ensure that hidden fields declared in camelCase are actually hidden and not exposed when models are turned into arrays.
public getHidden ( ) : array
Результат array

getOriginal() публичный Метод

Get the model's original attribute values.
public getOriginal ( string $key = null, mixed $default = null ) : array
$key string
$default mixed
Результат array

getSnakeKey() защищенный Метод

If the field names need to be converted so that they can be accessed by camelCase, then we can do that here.
protected getSnakeKey ( $key ) : string
$key
Результат string

getTrueKey() публичный Метод

Retrieves the true key name for a key.
public getTrueKey ( $key ) : string
$key
Результат string

isCamelCase() публичный Метод

Determines whether the model (or its parent) requires camelcasing. This is required for pivot models whereby they actually depend on their parents for this feature.
public isCamelCase ( ) : boolean
Результат boolean

relationsToArray() публичный Метод

Get the model's relationships, converting field casing if necessary.
public relationsToArray ( ) : array
Результат array

setAttribute() публичный Метод

Overloads the eloquent setAttribute method to ensure that fields accessed in any case are converted to snake_case, which is the defacto standard for field names in databases.
public setAttribute ( string $key, mixed $value )
$key string
$value mixed

toCamelCase() публичный Метод

Converts a given array of attribute keys to the casing required by CamelCaseModel.
public toCamelCase ( mixed $attributes ) : array
$attributes mixed
Результат array

toSnakeCase() публичный Метод

Converts a given array of attribute keys to the casing required by CamelCaseModel.
public toSnakeCase ( $attributes ) : array
$attributes
Результат array

Описание свойств

$enforceCamelCase публичное свойство

Alter eloquent model behaviour so that model attributes can be accessed via camelCase, but more importantly, attributes also get returned as camelCase fields.
public bool $enforceCamelCase
Результат boolean