The data pipeline configures how data objects are constructed from a payload. A normalized array is passed through multiple pipes that transform it into property values for the data object constructor.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.
Default Pipeline
The pipeline consists of these pipes by default:- AuthorizedDataPipe - Checks if the user is authorized to perform the request
- MapPropertiesDataPipe - Maps property names
- FillRouteParameterPropertiesDataPipe - Fills property values from route parameters
- ValidatePropertiesDataPipe - Validates properties
- DefaultValuesDataPipe - Adds default values for unset properties
- CastPropertiesDataPipe - Casts property values
Customizing the Pipeline
Define a custom pipeline for a data object:Creating a DataPipe
Implement theDataPipe interface:
Parameters
- payload - The non-normalized payload
- class -
DataClassobject for the data object (more info) - properties - Key-value properties for constructing the data object
- creationContext - Context containing:
dataClass- The data class being createdvalidationStrategy- The validation strategy in usemapPropertyNames- Whether property names should be mappeddisableMagicalCreation- Whether to use magical creation methodsignoredMagicalMethods- Which magical methods are ignoredcasts- Collection of global casts
Preparing Data for the Pipeline
Modify the payload after normalization but before entering the pipeline:Extending the Pipeline
Add a pipe at the beginning without creating a whole new pipeline:Pipeline and Magic Methods
When using magic creation methods, the pipeline is not used (since you manually control construction). Only when you pass a request object is a minimal version used for authorization and validation.