class Formatter

Properties

string $content_type The Content-Type this Formatter returns.
protected ModelMapping $mapping Holds the mapping used to determine the appropriate Transformer for each Model.
protected Controller $controller Holds the instanced of the calling controller.

Methods

__construct( ModelMapping $mapping, Controller $controller)

Create a new instance.

string
format( mixed $data)

Generate a HTTP response body from an Eloquent Collection or Model.

Array
formatResource( Model $model)

Format a single record.

Array
formatCollection( Collection $collection)

Format an entire collection.

String
serialize( Array $data)

Turn the transformed data into a JSON string.

Array
transform( Model $model)

Apply the transformer to an Eloquent Model.

Details

at line line 42
__construct( ModelMapping $mapping, Controller $controller)

Create a new instance.

Parameters

ModelMapping $mapping The ModelMapping to use to determine the correct Validator/Transformer for each formatted record
Controller $controller The controller instance that this call originates from

at line line 55
string format( mixed $data)

Generate a HTTP response body from an Eloquent Collection or Model.

Parameters

mixed $data An Eloquent Collection or Model

Return Value

string A response body

Exceptions

InvalidData In case the input is neither Model nor Collection

at line line 75
protected Array formatResource( Model $model)

Format a single record.

Parameters

Model $model The Eloquent Model instance to format

Return Value

Array

at line line 86
protected Array formatCollection( Collection $collection)

Format an entire collection.

Parameters

Collection $collection The Eloquent Collection to format

Return Value

Array

at line line 100
protected String serialize( Array $data)

Turn the transformed data into a JSON string.

Parameters

Array $data The raw data array

Return Value

String

at line line 111
protected Array transform( Model $model)

Apply the transformer to an Eloquent Model.

Parameters

Model $model The Eloquent Model instance to transform

Return Value

Array