PHP Trait Eloquence\Behaviours\CamelCasing

Afficher le fichier Open project: kirkbushell/eloquence

Méthodes publiques

Свойство Type Description
$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.

Méthodes publiques

Méthode Description
__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.

Méthodes protégées

Méthode Description
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.

Method Details

__isset() public méthode

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
Résultat mixed

__unset() public méthode

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
Résultat void

attributesToArray() public méthode

Return the attributes for the model, converting field casing if necessary.
public attributesToArray ( ) : array
Résultat array

getAttribute() public méthode

Retrieve a given attribute but allow it to be accessed via alternative case methods (such as camelCase).
public getAttribute ( string $key ) : mixed
$key string
Résultat mixed

getAttributes() public méthode

Converts the attributes to a camel-case version, if applicable.
public getAttributes ( $keys = [] ) : array
Résultat array

getDates() public méthode

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
Résultat array

getHidden() public méthode

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
Résultat array

getOriginal() public méthode

Get the model's original attribute values.
public getOriginal ( string $key = null, mixed $default = null ) : array
$key string
$default mixed
Résultat array

getSnakeKey() protected méthode

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
Résultat string

getTrueKey() public méthode

Retrieves the true key name for a key.
public getTrueKey ( $key ) : string
$key
Résultat string

isCamelCase() public méthode

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
Résultat boolean

relationsToArray() public méthode

Get the model's relationships, converting field casing if necessary.
public relationsToArray ( ) : array
Résultat array

setAttribute() public méthode

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() public méthode

Converts a given array of attribute keys to the casing required by CamelCaseModel.
public toCamelCase ( mixed $attributes ) : array
$attributes mixed
Résultat array

toSnakeCase() public méthode

Converts a given array of attribute keys to the casing required by CamelCaseModel.
public toSnakeCase ( $attributes ) : array
$attributes
Résultat array

Property Details

$enforceCamelCase public_oe property

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
Résultat boolean