class JsonapiFormatter extends Formatter

Properties

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

Methods

__construct( ModelMapping $mapping, Controller $controller)

Create a new instance.

from Formatter
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.

from Formatter
String
serialize( Array $data)

Turn the transformed data into a JSON string.

from Formatter
Array
transform( Model $model)

Apply the transformer to an Eloquent Model.

from Formatter
string
getModelType( Model $model)

master(Functional programming)

Details

in Formatter 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 16
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 44
protected Array formatResource( Model $model)

Format a single record.

Parameters

Model $model The Eloquent Model instance to format

Return Value

Array

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

Format an entire collection.

Parameters

Collection $collection The Eloquent Collection to format

Return Value

Array

in Formatter 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

in Formatter 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

at line line 84
protected string getModelType( Model $model)

master(Functional programming)

Parameters

Model $model

Return Value

string