Skip to main content
Normalizers transform payloads (like models, objects, or JSON) into arrays that can be used in the data pipeline.

Usage Example

Create a data object from an Eloquent model:
The normalizer converts the model into an array before it enters the pipeline.

Default Normalizers

Five normalizers are enabled by default:
  • ModelNormalizer - Casts Eloquent models
  • ArrayableNormalizer - Casts Arrayable objects
  • ObjectNormalizer - Casts stdObject instances
  • ArrayNormalizer - Casts arrays
  • JsonNormalizer - Casts JSON strings

Optional Normalizer

  • FormRequestNormalizer - Normalizes form requests by calling the validated() method

Configuration

Configure normalizers globally in config/data.php:

Per-Data-Class Configuration

Override normalizers for a specific data class:

Creating a Normalizer

Implement the Normalizer 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.