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

Define rich, typed data objects once and use them for requests, validation, API resources/transformers, and TypeScript definitions. Create from arrays/requests/models, apply rules automatically, and transform only what’s needed with lazy properties.

View on GitHub
Deep Wiki
Context7
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.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport