Resources: https://laravel.com/docs/6.x/eloquent-resources
Generate with php artisan make:api:resource UserResource
and php artisan make:api:resource UserResourceCollection
Change the Resource to extend from:
use Phpsa\LaravelApiController\Http\Resources\ApiResource
for your resource use Phpsa\LaravelApiController\Http\Resources\ApiCollection
for your resource collection
in your controller override the following params:
protected $resourceSingle = UserResource::class;
protected $resourceCollection = UserCollection::class;
The following properties are available on the resource object:
protected static $mapResources
- maps related resourcesprotected static $defaultFields = null;
- which fields are returned by defaultprotected static $allowedFields = null;
- which fields are allowed to be returnedprotected static $allowedScopes = null;
- which scopes should be callable.Use this middleware to convert all camel to snake: \Phpsa\LaravelApiController\Http\Middleware\SnakeCaseInputs
set your request header X-Accept-Case-Type
to either snake
or camel
to transform your data response keys to either snake or camel case.
In the controller the following methods can be overwritten: