Introduction
Installing and configuring Laravel Apiable into your Laravel application.
Install with the following command:
Getting started
First publish the config file once installed like this:
Then edit the resource_type_map
part including all your models like this:
If you see, this is same as Laravel's Relation::enforceMorphMap()
but reversed.
Setup your models
For more information about how to customise this check out Responses section.
This is a bit of manual work, but you need to setup your models in order for them to be JSON:API serializable entities:
You need to add that implements JsonApiable
to your class importing this class and the jsonApiableOptions
method.
Basic transformation usage
And, finally, use as simple as importing the class OpenSoutheners\LaravelApiable\Http\Resources\JsonApiCollection
for collections or OpenSoutheners\LaravelApiable\Http\Resources\JsonApiResource
for resources.
Error handling
When your application returns errors and your frontend only understand JSON:API, then these needs to be transform. So we've you cover, set them up by simply doing the following on your app/Exceptions/Handler.php
Last updated