Limiting rows
scopeWithAdminApiResponse() limits every API query of the model, also when the model is included as a relation of another model. scopeAdminRows() of the listing applies too.
app/Models/Order.php
Changing rows
setAdminApiResponse() is called for each returned row:
app/Models/Order.php
Scope filters
Public scopes declared on the model become filters. The value of the filter is passed as the parameter of the scope:app/Models/Product.php
Relations in responses
include uses the camelCase names of the relations, listed in /admin/api/v1/models. The response keys are snake_case, as Eloquent returns them:
filter[post_id]=5.
Other relations of the model
Relations which are not fields, child or parent models are not included, the API answers400 and the message names the $apiRelations property. List them there to allow them:
app/Models/Invoice.php
read permission and scopeAdminRows() of the related model apply as for other relations, and nested includes continue with the relations of the related model.
Localized values
With localization enabled, send theApp-Locale header to receive the values of one language. Without it, localized fields return all languages.
Tokens for integrations
Create a token with explicit abilities for a server integration:Custom response format
The request parameters and the response shapes come from a format class. The defaultAdminApi\Formats\Laravel\LaravelFormat follows Laravel API resources and the spatie query builder. Implement AdminApi\Formats\Format and bind it to use another convention, e.g. JSON:API:
app/Providers/AppServiceProvider.php