- Definition & Principles
- Folder Structure
- Code Sample
- Controller response builder helper functions
- All API Controller MUST extend from
- All Web Controller MUST extend from
- Controllers should only call the the
runmethod of Actions.
- Controllers should pass the Request object to the Action instead of passing data from the request.
In case you want to handle the same Action differently based on the UI type (e.g. API, Web, CLI) you can set the
UI on Action with
and get the UI in your Action with
Many helper function are there to help you build your response faster, those helpers exist in
transform This is the most useful function which you will be using in most cases.
- First required parameter accepts data as object or Collection of objects.
- Second required parameter is the transformer object
- Third optional parameter take the includes that should be returned by the response, ($availableIncludes and $defaultIncludes in the transformer class).
- Fourth optional parameter accepts metadata to be injected in the response.
withMeta This function allows including metadata in the response.
json This function allows passing array data to be represented as json.
- // Some functions might not be documented, so refer to the
vendor/apiato/core/Traits/ResponseTrait.phpand see the public functions.