NewYour coding agent can read the release notes before it upgrades.Set up the MCP server →
Packagist, #411 most downloaded on Packagist
Create unified resources and data transfer objects
Latest stable
4.23.1
Last release 27 days ago
26 Oct 2026
Release timing varies
gaps range from 9 days to 6 months
Nearly every release is documented
notes for 59 of the last 60 stable releases
Nothing withdrawn
no release was ever pulled
5 years old
137 releases · first in 2021
Drag across the ruler to compare, or tap a release to open it.
A new allowedClasses option for UnserializeCast , and a round of PHPStan fixes.
A new allowedClasses option for UnserializeCast, and a round of PHPStan fixes.
allowedClasses option to UnserializeCast (#1220)UnserializeCast called unserialize() without any restrictions, so every class in your application could be created from the serialized value. You can now limit which classes are allowed with the new allowedClasses option, which is passed to unserialize() as allowed_classes:
class SongData extends Data
{
public function __construct(
public string $title,
#[WithCast(UnserializeCast::class, allowedClasses: [SongMetadata::class])]
public SongMetadata $metadata,
) {
}
}Classes outside the list become a __PHP_Incomplete_Class object, and passing false only allows scalar values and arrays. The default stays true, so existing casts keep working as before. The cast is now also documented, including a note not to use it on user input.
Thanks @rubenvanassche.
PHPStan 2.3 stopped reporting a few errors that were in the baseline, which made the PHPStan workflow fail. The baseline is regenerated, a redundant check in DataMethod is removed, and the type assertion for cursor paginators is updated. There are no behaviour changes.
Thanks @rubenvanassche.
Full Changelog: 4.23.0...4.23.1
Your coding agent can read these notes before it upgrades. Set up the MCP server →
A round of bug fixes for validation rules, install resolution, and rule overrides.
A round of bug fixes for validation rules, install resolution, and rule overrides.
rules() overrides regardless of property defaults (#1187)Properties with a default value were silently dropping rules declared in the rules() method when the property was missing from the payload, so conditional rules like required, required_if, and prohibited_if never fired. The skip in DataValidationRulesResolver was originally there to stop auto-generated rules from rejecting empty payloads on all-default data classes (#441), but it also short-circuited explicit overrides.
Overrides are now resolved upfront, and the default-value skip only applies when no override exists for that property. #[WithoutValidation] no longer suppresses an override for the same key. If you wrote rules(), you own them. Thanks @rubenvanassche.
composer require spatie/laravel-data failed when Pest was already installed, because Pest's chain pulls phpdocumentor/reflection-docblock 6.0.3 while the phpdocumentor/reflection ^6.0 meta package hard-pinned reflection-docblock ^5. The meta package is now dropped in favour of direct dependencies on the three sub-packages we use, with widened constraints:
- "phpdocumentor/reflection" : "^6.0",
+ "phpdocumentor/type-resolver" : "^1.7 || ^2.0",
+ "phpdocumentor/reflection-common" : "^2.2",
+ "phpdocumentor/reflection-docblock" : "^5.3 || ^6.0",The phpDocumentor APIs we call are identical across both majors, so no code changes are required. Thanks @rubenvanassche.
Min, Max and Size validation attributes (#1185)The constructors typed their value as int|ExternalReference, and because those classes don't declare strict types, PHP silently coerced floats to int. #[Min(0.01)] became min:0, letting 0 pass validation, even though Laravel's validator accepts floats for these rules. Types are now widened to int|float|ExternalReference, mirroring MultipleOf:
#[Min(0.01), Max(99.99)]
public float $price;Digit-count rules (Digits, MinDigits, MaxDigits, DigitsBetween) and Password length stay int. Thanks @rubenvanassche.
Full Changelog: 4.22.1...4.23.0
Support Inertia v3 by falling back to OptionalProp by @jessegall in #1181
Full Changelog: 4.22.0...4.22.1
Full Changelog: https://github.com/spatie/laravel-data/compare/4.22.0...4.22.1
Add support for custom validation messages and attributes when using property morphable by @bentleyo in #1055
Full Changelog: 4.21.0...4.22.0
Full Changelog: https://github.com/spatie/laravel-data/compare/4.21.0...4.22.0
Fix deprecation warning for 'SplObjectStorage::attach' by @jelledruut in #1145
Full Changelog: 4.20.1...4.21.0
Full Changelog: https://github.com/spatie/laravel-data/compare/4.20.1...4.21.0
Fix an issue where the reflection dependency could not be resolved correctly
Laravel 13 support Livewire 4 support Dropped PHP 8.1 support
Fix deprecation warning for ReflectionProperty::getDefaultValue() by @evan-burrell in #1142
Full Changelog: 4.19.0...4.19.1
Full Changelog: https://github.com/spatie/laravel-data/compare/4.19.0...4.19.1
[fix] DataMorphClassResolver: skip default value applying if morph property was resolved by @litvintroll in #1101
Full Changelog: 4.18.0...4.19.0
Full Changelog: https://github.com/spatie/laravel-data/compare/4.18.0...4.19.0
Update issue template by @AlexVanderbist in #1080
Full Changelog: 4.17.1...4.18.0
Full Changelog: https://github.com/spatie/laravel-data/compare/4.17.1...4.18.0
Fix issue where toArray() is called on null collections by @oddvalue in https://github.com/spatie/laravel-data/pull/1054
Full Changelog: https://github.com/spatie/laravel-data/compare/4.17.0...4.17.1
Add support for external validation attribute references by @rubenvanassche in https://github.com/spatie/laravel-data/pull/1051
Full Changelog: https://github.com/spatie/laravel-data/compare/4.16.1...4.17.0
Fix issue where toArray() is called on null by @mdietger in https://github.com/spatie/laravel-data/pull/1046
Full Changelog: https://github.com/spatie/laravel-data/compare/4.16.0...4.16.1
Add return type annotations to TransformableData trait by @cyppe in https://github.com/spatie/laravel-data/pull/1000
Full Changelog: https://github.com/spatie/laravel-data/compare/4.15.3...4.16.0
Add support for only and except in enum rule
Full Changelog: https://github.com/spatie/laravel-data/compare/4.15.2...4.15.3
Fix: CannotCreateData exception when AutoWhenLoadedLazy relationship is not loaded
Full Changelog: https://github.com/spatie/laravel-data/compare/4.15.1...4.15.2
Fix #997 by @bentleyo in https://github.com/spatie/laravel-data/pull/998
Full Changelog: https://github.com/spatie/laravel-data/compare/4.15.0...4.15.1
Add test and doc changes by @rubenvanassche in https://github.com/spatie/laravel-data/pull/996
Full Changelog: https://github.com/spatie/laravel-data/compare/4.14.1...4.15.0
fix: Model with method name matching attribute names are not retrieved by @Tofandel in https://github.com/spatie/laravel-data/pull/979
Full Changelog: https://github.com/spatie/laravel-data/compare/4.14.0...4.14.1
If you're using cached versions of your data objects and don't clear this cache on deploy, now is the time since we've updated some internal structure
If you're using cached versions of your data objects and don't clear this cache on deploy, now is the time since we've updated some internal structures.
Some internals structures (attributes) in the DataProperty and DataClass have changed, if you're using these classes, update them accordingly.
Fix an issue where specific Lazy classes won't be recognized
Full Changelog: https://github.com/spatie/laravel-data/compare/4.13.1...4.13.2
Bump dependabot/fetch-metadata from 2.2.0 to 2.3.0 by @dependabot in https://github.com/spatie/laravel-data/pull/940
Allow Laravel 12
Full Changelog: https://github.com/spatie/laravel-data/compare/4.13.0...4.13.1
Auto lazy by @rubenvanassche in https://github.com/spatie/laravel-data/pull/831
Full Changelog: https://github.com/spatie/laravel-data/compare/4.12.0...4.13.0
What a release! Probably to biggest minor release we've ever done!
What a release! Probably to biggest minor release we've ever done!
Some cool highlights:
Optional values are great, but sometimes a null value is desirable from now on you can do the following:
class SongData extends Data {
public function __construct(
public string $title,
public string $artist,
public Optional|null|string $album,
) {
}
}
SongData::factory()
->withoutOptionalValues()
->from(['title' => 'Never gonna give you up', 'artist' => 'Rick Astley']); // album will `null` instead of `Optional`
It was already possible to inject a Laravel route parameter when creating a data object, we've now extended this functionality quite a bit and also allow injecting dependencies from the container and the authenticated user.
class SongData extends Data {
#[FromAuthenticatedUser]
public UserData $user;
}
In the past when the validation rules of a property were manually defined, the automatic validation rules for that property were omitted. From now on, you can define manual validation rules and merge them with the automatically generated validation rules:
```php
#[MergeValidationRules]
class SongData extends Data
{
public function __construct(
public string $title,
public string $artist,
) {
}
public static function rules(): array
{
return [
'title' => ['max:20'],
'artist' => ['max:20'],
];
}
}
We now ship by default a Uppercase and Lowercase mapper for mapping property names.
Data::authorize() to allow for dependencies by @cosmastech in https://github.com/spatie/laravel-data/pull/910LowerCaseMapper and UpperCaseMapper by @andrey-helldar in https://github.com/spatie/laravel-data/pull/927Full Changelog: https://github.com/spatie/laravel-data/compare/4.11.1...4.12.0
What a release! Probably to biggest minor release we've ever done!
Some cool highlights:
Optional values are great, but sometimes a null value is desirable from now on you can do the following:
class SongData extends Data {
public function __construct(
public string $title,
public string $artist,
public Optional|null|string $album,
) {
}
}
SongData::factory()
->withoutOptionalValues()
->from(['title' => 'Never gonna give you up', 'artist' => 'Rick Astley']); // album will `null` instead of `Optional`
It was already possible to inject a Laravel route parameter when creating a data object, we've now extended this functionality quite a bit and also allow injecting dependencies from the container and the authenticated user.
class SongData extends Data {
#[FromAuthenticatedUser]
public UserData $user;
}
In the past when the validation rules of a property were manually defined, the automatic validation rules for that property were omitted. From now on, you can define manual validation rules and merge them with the automatically generated validation rules:
```php
#[MergeValidationRules]
class SongData extends Data
{
public function __construct(
public string $title,
public string $artist,
) {
}
public static function rules(): array
{
return [
'title' => ['max:20'],
'artist' => ['max:20'],
];
}
}
We now ship by default a Uppercase and Lowercase mapper for mapping property names.
Data::authorize() to allow for dependencies by @cosmastech in https://github.com/spatie/laravel-data/pull/910LowerCaseMapper and UpperCaseMapper by @andrey-helldar in https://github.com/spatie/laravel-data/pull/927Full Changelog: https://github.com/spatie/laravel-data/compare/4.11.1...4.12.0
Full Changelog: https://github.com/spatie/laravel-data/compare/4.10.1...4.11.0
It has been a fews weeks, a mostly bugfix release with one new feature, enjoy!
Full Changelog: https://github.com/spatie/laravel-data/compare/4.7.2...4.8.0
Full Changelog: https://github.com/spatie/laravel-data/compare/4.7.0...4.7.1
Full Changelog: https://github.com/spatie/laravel-data/compare/4.6.0...4.7.0
Full Changelog: https://github.com/spatie/laravel-data/compare/4.5.1...4.6.0
Full Changelog: https://github.com/spatie/laravel-data/compare/4.5.1...3.12.0
Full Changelog: https://github.com/spatie/laravel-data/compare/4.5.0...4.5.1
DataCollectable transformation by @innocenzi in https://github.com/spatie/laravel-data/pull/696date_format rule by @riesjart in https://github.com/spatie/laravel-data/pull/727list validation rule by @riesjart in https://github.com/spatie/laravel-data/pull/728Full Changelog: https://github.com/spatie/laravel-data/compare/4.4.1...4.5.0
Full Changelog: https://github.com/spatie/laravel-data/compare/4.4.0...4.4.1
Full Changelog: https://github.com/spatie/laravel-data/compare/4.3.2...4.4.0
Full Changelog: https://github.com/spatie/laravel-data/compare/4.3.1...4.3.2
null for fieldContext within resolvePotentialPartialArray by @faustbrian in https://github.com/spatie/laravel-data/pull/693Full Changelog: https://github.com/spatie/laravel-data/compare/4.3.0...4.3.1
Full Changelog: https://github.com/spatie/laravel-data/compare/4.2.0...4.3.0
Full Changelog: https://github.com/spatie/laravel-data/compare/4.1.0...4.2.0
Full Changelog: https://github.com/spatie/laravel-data/compare/3.11.0...3.11.1
getRule to fix issues with caching and typescript transformernull or an empty arraynull to collect and return an empty version of the defined output typeLaravel-data 4.0.0 was released 5 hours ago, time for an update!
PropertyRulesfrom without parametersSome more "internal" changes
A fresh release after a month of vacation, enjoy!
CustomValidationAttribute'smake:data command (#449, #335)StudlyMapperVersion 2 of laravel-data is a complete overhaul, we've almost completely rewritten the package.
This is a (non-complete) list of the new features:
only and except methods on Data and DataCollectionsFull Changelog: https://github.com/spatie/laravel-data/compare/1.4.7...1.5.0
links array to the paginated responselazy::whenLoaded closure when the relation is nullWithoutValidation attributeisBuiltIn from DataPropertyFull Changelog: https://github.com/spatie/laravel-data/compare/1.3.2...1.3.3
Enumauthorized method to authorizeRequest object is given not only when a data object is injectedDataFromRequestResolverDataValidatorResolverspatie/test-time dependency to require-devWithData trait for quicker getting data from objectsFix an issue where the cache structures command did not work if the directory did not exist
feat: support "null to optional" by @innocenzi in https://github.com/spatie/laravel-data/pull/881
Full Changelog: https://github.com/spatie/laravel-data/compare/4.10.1...4.11.0
Fix an issue where optional default values would disable validation
It has been a fews weeks, a mostly bugfix release with one new feature, enjoy!
It has been a fews weeks, a mostly bugfix release with one new feature, enjoy!
Move some interfaces around in order to avoid a circular chaos
- Remove a circular dependency
Nothing published for this version
Detect data from collection by @clementbirkle in https://github.com/spatie/laravel-data/pull/812
Full Changelog: https://github.com/spatie/laravel-data/compare/4.7.2...4.8.0
Fix issue where an exception was not always thrown while it should
Fix some typos in docs by @Klaas058 in https://github.com/spatie/laravel-data/pull/794
Full Changelog: https://github.com/spatie/laravel-data/compare/4.7.0...4.7.1
Fix typo in docs by @DvDty in https://github.com/spatie/laravel-data/pull/769
Full Changelog: https://github.com/spatie/laravel-data/compare/4.6.0...4.7.0
Add initial support for casting union types
Full Changelog: https://github.com/spatie/laravel-data/compare/4.5.1...4.6.0
Abstract data object as collection by @onursimsek in https://github.com/spatie/laravel-data/pull/741
Full Changelog: https://github.com/spatie/laravel-data/compare/4.5.0...4.5.1
Cast value to string for createFromFormat by @kylekatarnls in https://github.com/spatie/laravel-data/pull/707
DataCollectable transformation by @innocenzi in https://github.com/spatie/laravel-data/pull/696date_format rule by @riesjart in https://github.com/spatie/laravel-data/pull/727list validation rule by @riesjart in https://github.com/spatie/laravel-data/pull/728Full Changelog: https://github.com/spatie/laravel-data/compare/4.4.1...4.5.0
fix issue where DataCollection keys were missing in TypeScript by @rubenvanassche
Full Changelog: https://github.com/spatie/laravel-data/compare/4.4.0...4.4.1
Add support for transformation max depths by @rubenvanassche in https://github.com/spatie/laravel-data/pull/699
Full Changelog: https://github.com/spatie/laravel-data/compare/4.3.2...4.4.0
Provide fallbacks for config values by @sebastiandedeyne in https://github.com/spatie/laravel-data/pull/695
Full Changelog: https://github.com/spatie/laravel-data/compare/4.3.1...4.3.2
Support duration in cache configuration by @sebastiandedeyne in https://github.com/spatie/laravel-data/pull/694
null for fieldContext within resolvePotentialPartialArray by @faustbrian in https://github.com/spatie/laravel-data/pull/693Full Changelog: https://github.com/spatie/laravel-data/compare/4.3.0...4.3.1
Update wrapping.md to clarify collections and paginated collections case by @santigarcor in https://github.com/spatie/laravel-data/pull/675
Full Changelog: https://github.com/spatie/laravel-data/compare/4.2.0...4.3.0
Add experimental support for Livewire synths @rubenvanassche in https://github.com/spatie/laravel-data/pull/669
Full Changelog: https://github.com/spatie/laravel-data/compare/4.1.0...4.2.0
Fix an issue where the cache was queried too much
getRule to fix issues with caching and typescript transformerFixes issue where casts could not return null or an empty array
null or an empty arraynull to collect and return an empty version of the defined output typeLaravel-data 4.0.0 was released 5 hours ago, time for an update!
Laravel-data 4.0.0 was released 5 hours ago, time for an update!
PropertyRulesAllow arrays, Collections, Paginators, ... to be used as DataCollections
from without parametersSome more "internal" changes
Backport cache fix to v3 by @jameshulse in https://github.com/spatie/laravel-data/pull/671
Full Changelog: https://github.com/spatie/laravel-data/compare/4.5.1...3.12.0
fix: adds environment variable to disable structure caching
Backport cache fix to v3 by @jameshulse in https://github.com/spatie/laravel-data/pull/671
Full Changelog: https://github.com/spatie/laravel-data/compare/3.11.0...3.11.1
Add support for data structure caching #622
Improve performance when optional peoperty exists
A fresh release after a month of vacation, enjoy!
A fresh release after a month of vacation, enjoy!
Fix breaking compatibility #590
Add Declined and DeclinedIf validation attributes
Fix an issue where computed values could not be set as null
CustomValidationAttribute's- fix abstract json cast format
Add Null value support for RequiredUnless Validation
fix target namespace when creating files with Laravel Idea
One column per quarter.