Reference
Value helpers
Every value helper and modifier available in the hooks of a resource.
Called on $this in a hook. The first argument is the key read on the model (the member name by default) or a closure
receiving the model. Each returns a descriptor of ark4ne/laravel-api-revisions. See
Attributes & values for examples.
Helpers
| Helper | Renders | Own modifiers |
|---|---|---|
bool() | a boolean | |
integer() | an integer | |
float() | a float | precision(int), truncate(), min(), max() |
string() | a string | format('email') |
date() | a date without time, Y-m-d | format('d/m/Y') |
datetime() | a date and time, revisions.date_time_format (ATOM) | format('Y-m-d H:i') |
time() | a time of day, H:i:s | format('H:i') |
decimal() | an exact decimal as a string ("12.50") | scale(2) |
uuid(), ulid() | a string with its format | |
json() | a JSON string, decoded | |
array() | a list of values of any type | |
arrayOf($this->string(), 'tags') | a typed list | |
enum(State::class) | the value of a backed enum | |
struct(['city' => $this->string()], 'address') | an object of described members | |
mixed() | the value as it is | |
a name registered in TypeRegistry | a type of the application: $this->money('price') | its own |
Modifiers of every value
Each returns a copy.
| Modifier | Effect |
|---|---|
->nullable(bool $nullable = true) | null renders null; not nullable, null is a value error |
->when(Closure $condition) | Rendered only when the closure returns true; receives ($model, $attribute), runs before the value is read |
->unless(Closure $condition) | Left out when the closure returns a truthy value |
->whenNotNull() | Left out when null |
->whenFilled() | Left out when empty |
->whenHas(?string $key = null) | Left out when the model has no such attribute |
->whenLoaded(string $relation) | Left out unless the relation is loaded |
->whenAppended(?string $attribute = null) | Rendered only when the accessor is appended |
->whenInFields() | Left out unless fields[type] names it explicitly |
->describe('…'), ->example(…), ->deprecated() | Documentation of the field |
->was(Revision $revision, name: …, schema: …, down: …) | What the field was up to $revision included |
->since(Revision $revision), ->until(Revision $revision) | The field exists from / up to $revision included |
Conditional helpers of a resource
| Helper | Effect |
|---|---|
$this->applyWhen(Closure $condition, array $members) | Members rendered when the closure holds for the resource |
$this->whenInFields(Request $request, string $attribute, Descriptor|Closure $value) | A value rendered only when fields requests the attribute |
$this->whenInIncludes(Request $request, string $relationship, Descriptor|Closure $value) | A value rendered only when include names the relationship |
Properties of a resource
| Property | Effect |
|---|---|
protected ?bool $autoWhenHas = true; | whenHas() on every value read from a key of the model |
protected ?bool $autoWhenIncluded = true; | whenIncluded() on every relationship |