Minimal Resource
Hook Reference
init(): void (required)
Declare all data properties with $this->addProperty(...). This includes the resource identifier — it is a regular property like any other, declared first by convention. The constructor is final — all setup happens here.
getName(): string (required)
Singular resource name. Used in descriptions (“Create animal”) and OpenAPI response names.
getPluralName(): string (optional)
Defaults to getName() . 's'. Override for irregular plurals:
excludeFromMode(string $mode): array (required)
Return property names to exclude from a given mode. Typical uses:
- Hide
passwordfrom every response. - Hide
weightfrom list responses only. - Exclude
animal_uuidfrom create request bodies (the server generates the identifier; useMODE_CREATEto suppress it from the body documentation).
AbstractResource: MODE_CREATE, MODE_VIEW, MODE_UPDATE, MODE_DELETE, MODE_LIST.
availableFilters(): FilterInterface[]
Declare filters exposed on the list endpoint:
$request->filtering()->status.
availableSortings(): Sort[]
Declare sortable fields for the list endpoint:
?order_by=... field not in this list is rejected by the validation middleware with a 422.
tags(): TagObject[]
OpenAPI tags for grouping operations.
Working with Instances
Controllers build resource instances from requests and arrays:getRoute(). Read it directly from the request and set it on the resource if needed: