Skip to content

API reference ​

Use Mattmy\FillMap\AttributeMapper to start a mapping. Mattmy\FillMap\MappingSource represents the input captured for mapping. Mattmy\FillMap\InputKeyStyle supplies the Exact, Camel, Snake, Pascal, and Kebab naming rules.

Capture input and choose a model ​

SignatureResult
AttributeMapper::from(array|FormRequest $input): MappingSourceCaptures prepared attributes or a Form Request's validated data.
AttributeMapper::fromRequestInput(Request $request, array $keys): MappingSourceCaptures the named top-level keys present in the parsed body. $keys is a list of non-empty strings.
MappingSource::forModel(string|Model $model): AttributeMapperStarts a mapping for an Eloquent model instance or a class constructible without arguments.

See Choosing and mapping input.

Configure a mapping ​

Each method returns an AttributeMapper with that branch's settings.

SignatureEffect
inputKeys(InputKeyStyle $style): selfSelects the naming style for the chain.
aliases(array $aliases): selfSet source keys for specific attributes. Pass all aliases at once.
merge(array $attributes): selfAdds or overwrites attributes with an application-provided map of model attribute names to values.
setId(mixed $value = null, mixed $attribute = 'id'): selfAdds a positive integer ID, or integer zero if the value is omitted or null.
setUuid(mixed $value = null, mixed $attribute = 'uuid'): selfAdds a UUID string from a valid string, a UuidInterface, or Laravel's UUID generator when the value is omitted or null.
only(mixed $attributes): selfKeeps the named model attributes.
except(mixed $attributes): selfExcludes the named model attributes.
withoutBlank(mixed $attributes = null): selfRemoves blank values from the named attributes, or from all attributes when omitted or null.

See Building the output for valid argument types, overwrite rules, and filter behavior.

Get the output ​

SignatureResult
toArray(): arrayAn array<string, mixed> of model attribute names and values.
collect(): CollectionAn Illuminate\Support\Collection<string, mixed> of the same attributes.
toModel(): ModelReturns a new filled model for a class target, or updates and returns the model instance you supplied.

See Configuration and errors for InvalidArgumentException, Laravel errors, and the attribute-mapper-config publish tag.