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

HelperRendersOwn modifiers
bool()a boolean
integer()an integer
float()a floatprecision(int), truncate(), min(), max()
string()a stringformat('email')
date()a date without time, Y-m-dformat('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:sformat('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 TypeRegistrya type of the application: $this->money('price')its own

Modifiers of every value

Each returns a copy.

ModifierEffect
->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

HelperEffect
$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

PropertyEffect
protected ?bool $autoWhenHas = true;whenHas() on every value read from a key of the model
protected ?bool $autoWhenIncluded = true;whenIncluded() on every relationship