Normalizers transform payloads (like models, objects, or JSON) into arrays that can be used in the data pipeline.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/spatie/laravel-data/llms.txt
Use this file to discover all available pages before exploring further.
Usage Example
Create a data object from an Eloquent model:Default Normalizers
Five normalizers are enabled by default:- ModelNormalizer - Casts Eloquent models
- ArrayableNormalizer - Casts
Arrayableobjects - ObjectNormalizer - Casts
stdObjectinstances - ArrayNormalizer - Casts arrays
- JsonNormalizer - Casts JSON strings
Optional Normalizer
- FormRequestNormalizer - Normalizes form requests by calling the
validated()method
Configuration
Configure normalizers globally inconfig/data.php:
Per-Data-Class Configuration
Override normalizers for a specific data class:Creating a Normalizer
Implement theNormalizer interface:
Example Implementation
Return Value
- Return an array if the normalizer can normalize the payload
- Return null if the normalizer cannot handle the payload
Execution Order
Normalizers execute in the order defined. The first normalizer that doesn’t return null is used.Magical creation methods always have precedence over normalizers.