Skip to main content

Minimal Resource

The resource is a pure data shape — no URL knowledge, no routing. URLs live in controllers.

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 password from every response.
  • Hide weight from list responses only.
  • Exclude animal_uuid from create request bodies (the server generates the identifier; use MODE_CREATE to suppress it from the body documentation).
Modes are constants on AbstractResource: MODE_CREATE, MODE_VIEW, MODE_UPDATE, MODE_DELETE, MODE_LIST.

availableFilters(): FilterInterface[]

Declare filters exposed on the list endpoint:
Each filter becomes a typed query parameter with full OpenAPI documentation and is accessible in the controller as $request->filtering()->status.

availableSortings(): Sort[]

Declare sortable fields for the list endpoint:
Any ?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:
For view / update / delete, the identifier is a path parameter declared in getRoute(). Read it directly from the request and set it on the resource if needed:
Serialize per mode:
Fields are accessed as dynamic properties:
With the docblock generator run, these also autocomplete in your IDE.