- Definition & Principles
- Folder Structure
- Code Samples
- Relationships (include)
- Transformer Available helper functions:
Read from the Porto SAP Documentation (#Transformers).
All API responses MUST be formatted via a Transformer.
Every Transformer SHOULD extend from
Each Transformer MUST have a
Reward Transformer with Country relation:
Usage from Controller (Single Item)
Usage from Controller (Multiple Items/Collection)
Loading relationships in Transformer (calling other Transformers):
This can be done in 2 ways:
By the User, he can specify what relations to return in response.
By the Developer, define what relations to include at run time.
You can request data with their relationships directly from the API call using
include=tags,user but first the Transformer need to have the
availableIncludes defined with their functions like this:
Now to get the
Tags with the response when Accounts are requested pass the
?include=tags parameter with the [GET] request.
To get Tags with User use the comma separator:
From the controller you can dynamically set the
DefaultInclude using (
setDefaultIncludes) anytime you want.
You need to have
includeTags function defined on the transformer. Look at the full examples above.
If you want to include a relation with every response from this transformer you can define the relation directly in the transformer on (
You need to have
includeTags functions defined on the transformer. Look at the full examples above.
user(): returns current authenticated user object.
ifAdmin($adminResponse, $clientResponse): merges normal client response with the admin extra or modified results, when current authenticated user is Admin.
For more information about the Transformers read this.