You are viewing the documentation for an older version of this package. You can check the version you are using with the following command:
composer show spatie/laravel-data
Normalizers
This package allows you to dynamically create data objects from any kind of object. For example, you can use an
eloquent model to create a data object like this:
SongData::from(Song::findOrFail($id));
A Normalizer will take a payload like a model and will transform it into an array so it can be used in the pipeline (see further).
By default, there are five normalizers for each data object:
ModelNormalizer will cast eloquent models
ArrayableNormalizer will cast Arrayable's
ObjectNormalizer will cast stdObject's
ArrayNormalizer will cast arrays
JsonNormalizer will cast json strings
Normalizers can be globally configured in config/data.php, and can be configured on a specific data object by overriding the normalizers method.
Normalizers are executed the order as they are defined in the normalize method. The first normalizer not returning null will be used to normalize the payload. Magical creation methods always have precedence on normalizers.