Transformer
class Transformer
Responsible for applying transformations to Eloquent Models in order to customize their representation at the API.
Properties
protected array | $aliases | Attributes or relations that shall appear under a different key in the output. | |
protected array | $drop_attributes | Name the attributes that shall be omitted from the output. | |
protected array | $drop_relations | Name the relations that shall be omitted from the output. | |
protected ModelMapping | $model_mapping | Stores an instance of a model_mapping to retrieve transformers for related models. | |
protected Model | $model | Holds the eloquent instance to be transformed. | |
protected Array | $output | Holds the array form of the model. |
Methods
No description
Transform a single eloquent record.
Add the relations to the output.
Add a single relation.
Transform either Collection or Model using the known $model_mapping.
No description
Format all attributes if a function exists that matches their name.
Apply all rules in $this->aliases and replace key accordingly in output.
Here you can hook in to change the output before serializing.
Serialize a single record to an array.
Details
at line line 58
__construct(
ModelMapping $model_mapping)
at line line 69
array
transform(
Model $model)
Transform a single eloquent record.
at line line 90
protected
void
handleRelations()
Add the relations to the output.
at line line 106
protected
addRelation(
String $name,
Model|Collection $relation)
Add a single relation.
at line line 117
protected
Array
transformAny(
Collection|Model $thing)
Transform either Collection or Model using the known $model_mapping.
at line line 132
protected
dropAttributes()
at line line 146
protected
void
formatAttributes()
Format all attributes if a function exists that matches their name.
If you want to transform the attribute post_type
, just define a
formatPostType
method that takes the old value of the
attribute and returns a new one.
at line line 162
protected
void
alias()
Apply all rules in $this->aliases and replace key accordingly in output.
at line line 177
protected
void
beforeSerialize()
Here you can hook in to change the output before serializing.
at line line 184
protected
Array
serialize()
Serialize a single record to an array.