Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Laravel Data Laravel Package

spatie/laravel-data

Create rich, typed data objects for Laravel that replace form requests and API transformers. Automatically map from requests, validate with inferred rules, transform to resources (with lazy/partial fields), and generate TypeScript definitions from the same source.

View on GitHub
Deep Wiki
Context7
4.23.0

A round of bug fixes for validation rules, install resolution, and rule overrides.

Run 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.

Fix install conflict on PHP 8.4 with Pest installed (#1186)

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.

Allow float values for 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.

What's Changed

Full Changelog: https://github.com/spatie/laravel-data/compare/4.22.1...4.23.0

4.22.1

What's Changed

Full Changelog: https://github.com/spatie/laravel-data/compare/4.22.0...4.22.1

4.22.0

What's Changed

Full Changelog: https://github.com/spatie/laravel-data/compare/4.21.0...4.22.0

4.21.0

What's Changed

Full Changelog: https://github.com/spatie/laravel-data/compare/4.20.1...4.21.0

4.20.1
  • Fix an issue where the reflection dependency could not be resolved correctly
4.20.0
  • Laravel 13 support
  • Livewire 4 support
  • Dropped PHP 8.1 support
4.19.1

What's Changed

Full Changelog: https://github.com/spatie/laravel-data/compare/4.19.0...4.19.1

4.19.0

What's Changed

Full Changelog: https://github.com/spatie/laravel-data/compare/4.18.0...4.19.0

4.18.0

What's Changed

Full Changelog: https://github.com/spatie/laravel-data/compare/4.17.1...4.18.0

4.17.1

What's Changed

Full Changelog: https://github.com/spatie/laravel-data/compare/4.17.0...4.17.1

4.17.0

What's Changed

Breaking changes

Full Changelog: https://github.com/spatie/laravel-data/compare/4.16.1...4.17.0

4.16.1

What's Changed

Full Changelog: https://github.com/spatie/laravel-data/compare/4.16.0...4.16.1

4.16.0

What's Changed

Full Changelog: https://github.com/spatie/laravel-data/compare/4.15.3...4.16.0

4.15.3
  • Add support for only and except in enum rule

Full Changelog: https://github.com/spatie/laravel-data/compare/4.15.2...4.15.3

4.15.2
  • Fix: CannotCreateData exception when AutoWhenLoadedLazy relationship is not loaded (#1009)
  • Fix: Inertia deferred properties not being that flexible

Full Changelog: https://github.com/spatie/laravel-data/compare/4.15.1...4.15.2

4.14.1

What's Changed

Full Changelog: https://github.com/spatie/laravel-data/compare/4.14.0...4.14.1

4.14.0

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 data classes could not be cached (a7d117e1224258a05c2d8e101928b6740a680a69)
  • Fix retrieval of property to work for Astrotomic/translatable (#883)
  • Refactored some internals for storing attribute information
  • Add dataClass to normalize exception message (#968)
  • Add Macroable Trait to Data Collection Classes (#971)
4.13.2

What's Changed

  • 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

4.13.1

Allow Laravel 12

What's Changed

New Contributors

Full Changelog: https://github.com/spatie/laravel-data/compare/4.13.0...4.13.1

4.12.0

What a release! Probably to biggest minor release we've ever done!

Some cool highlights:

Disabling optional values

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`

Injecting property values

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;
}

Merging manual rules

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'],
        ];
    }
}

New property mappers:

We now ship by default a Uppercase and Lowercase mapper for mapping property names.

All changes:

Full Changelog: https://github.com/spatie/laravel-data/compare/4.11.1...4.12.0

4.11.1
  • Fix an issue where the cache structures command did not work if the directory did not exist (#892)
4.10.1
  • Fix an issue where optional default values would disable validation
4.10.0

It has been a fews weeks, a mostly bugfix release with one new feature, enjoy!

  • Fix an issue where required rules could not be combined with optional (#844)
  • Fix Livewire return type to make sure it can return everything in the data object (#836)
  • Fix issue where validation messages where ignored by collections nested in collections (#867)
  • Fix Resource to include Contextable data inteface (#868)
  • Stop NormalizedModel from initializing itself and try to lazy load properties when required (#870)
  • Passing an enum to caster handle without an error (#841)
  • Passing date objects to caster handle without an error (#842)
  • Allow setting a default mapping strategy (#846)
4.9.0
  • Move some interfaces around in order to avoid a circular chaos
4.8.2
  • Remove a circular dependency
4.8.1
  • Fix a missing dependency
4.8.0

What's Changed

Full Changelog: https://github.com/spatie/laravel-data/compare/4.7.2...4.8.0

4.7.2
  • Fix issue where an exception was not always thrown while it should (#809)
  • Solve an issue where an empty container with an iterable cast won't be cast (#810)
  • Fix Parsing of Optional Types Annotations in DataIterableAnnotation (#808)
  • Support TypeScript Hidden Properties (#820)
  • Fix issue where abstract eloquent casts were not encrypted(#828)
4.7.1

What's Changed

New Contributors

Full Changelog: https://github.com/spatie/laravel-data/compare/4.7.0...4.7.1

4.7.0

What's Changed

New Contributors

Full Changelog: https://github.com/spatie/laravel-data/compare/4.6.0...4.7.0

4.6.0

What's Changed

  • Add initial support for casting union types
  • Fix an issue with paginator includes not working
  • Fix consistency of After, AfterOrEqual, Before, BeforeOrEquals rules
  • Fix creation context issue (#749)
  • Fix an performance issue where when creating a data object from models, the attributes were always called
  • Add a #[LoadRelation] attribute which allows loading model relations when creating data objects on the fly

Full Changelog: https://github.com/spatie/laravel-data/compare/4.5.1...4.6.0

3.12.0

What's Changed

Full Changelog: https://github.com/spatie/laravel-data/compare/4.5.1...3.12.0

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui
babelqueue/php-sdk
facebook/capi-param-builder-php
babelqueue/symfony
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle