Skip to content

Releases: spatie/laravel-data

4.12.0

24 Jan 13:25
b6f63fa
Compare
Choose a tag to compare

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:

  • Fix GitHub action fail by @rust17 in #918
  • Point to the right problem on ArgumentCountError exception by @nsvetozarevic in #884
  • Fix an issue where anonymous classes in castables were serialized (#903) by @rubenvanassche in #923
  • Add the ability to optionally merge automatically inferred rules with manual rules by @CWAscend in #848
  • Implement enum json serialization by @dont-know-php in #896
  • Use comments instead of docblocks in configuration file. by @edwinvdpol in #904
  • Casting DateTimeInterface: Truncate nanoseconds to microseconds (first 6 digits) / with Tests by @yob-yob in #908
  • Use container to call Data::authorize() to allow for dependencies by @cosmastech in #910
  • Improve type for CreationContextFactory::alwaysValidate by @sanfair in #925
  • Removed comma character from Data Rule stub by @andrey-helldar in #926
  • Use BaseData contract i/o Data concrete in CollectionAnnotation by @riesjart in #928
  • New mappers added: LowerCaseMapper and UpperCaseMapper by @andrey-helldar in #927
  • Allow disabling default Optional values in CreationContext by @ragulka in #931
  • Fix introduction.md by @pikant in #937
  • General code health improvements by @xHeaven in #920
  • Filling properties from current user by @c-v-c-v in #879

Full Changelog: 4.11.1...4.12.0

4.11.1

23 Oct 07:16
df5b58b
Compare
Choose a tag to compare
  • Fix an issue where the cache structures command did not work if the directory did not exist (#892)

4.11.0

22 Oct 11:21
fab1c51
Compare
Choose a tag to compare

What's Changed

Full Changelog: 4.10.1...4.11.0

4.10.1

07 Oct 08:41
d3113c6
Compare
Choose a tag to compare
  • Fix an issue where optional default values would disable validation

4.10.0

04 Oct 12:52
01eea07
Compare
Choose a tag to compare

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

10 Sep 13:45
1b7c105
Compare
Choose a tag to compare
  • Move some interfaces around in order to avoid a circular chaos

4.8.2

30 Aug 13:58
1732519
Compare
Choose a tag to compare
  • Remove a circular dependency

4.8.1

13 Aug 14:01
597961b
Compare
Choose a tag to compare
  • Fix a missing dependency

4.8.0

13 Aug 13:23
6fc4ed6
Compare
Choose a tag to compare

What's Changed

  • Detect data from collection by @clementbirkle in #812
  • Fix an issue where dd or dump did not work

Full Changelog: 4.7.2...4.8.0

4.7.2

25 Jul 11:25
8980ee5
Compare
Choose a tag to compare
  • 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)