Skip to content

Commit

Permalink
Merge branch 'main' of github.com:spatie/laravel-data-resource
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenvanassche committed Jun 13, 2024
2 parents d654740 + 34933c4 commit c49ce35
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 5 deletions.
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@

All notable changes to `laravel-data` will be documented in this file.

## 4.6.0 - 2024-05-03

### 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 - 2024-04-24

### What's Changed
Expand Down
3 changes: 2 additions & 1 deletion docs/advanced-usage/creating-a-cast.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ namespace Spatie\LaravelData\Tests\Fakes\Castables;

use Spatie\LaravelData\Casts\Cast;
use Spatie\LaravelData\Casts\Castable;
use Spatie\LaravelData\Support\Creation\CreationContext;
use Spatie\LaravelData\Support\DataProperty;

class Email implements Castable
Expand All @@ -82,7 +83,7 @@ class Email implements Castable
public static function dataCastUsing(...$arguments): Cast
{
return new class implements Cast {
public function cast(DataProperty $property, mixed $value, array $context): mixed {
public function cast(DataProperty $property, mixed $value, array $properties, CreationContext $context): mixed
return new Email($value);
}
};
Expand Down
6 changes: 4 additions & 2 deletions docs/advanced-usage/use-with-livewire.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,12 @@ requests the includes should be permanent.
It is possible to query lazy nested data objects, it is however not possible to query lazy properties which are not a data:

```php
use Spatie\LaravelData\Lazy;class LazySongData extends Data
use Spatie\LaravelData\Lazy;

class LazySongData extends Data
{
public function __construct(
public Lazy|ArristData $artist,
public Lazy|ArtistData $artist,
public Lazy|string $title,
) {}
}
Expand Down
2 changes: 1 addition & 1 deletion docs/as-a-data-transfer-object/casts.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,5 +160,5 @@ ReleaseData::from([
For this feature to work, a cast should not only implement the `Cast` interface but also the `IterableItemCast`. The
signatures of the `cast` and `castIterableItem` methods are exactly the same, but they're called on different times.
When casting a property like a DateTime from a string, the `cast` method will be used, when transforming an iterable
property like an arrat or Laravel Collection where the iterable item is typed using an annotation, then each item of the
property like an array or Laravel Collection where the iterable item is typed using an annotation, then each item of the
provided iterable will trigger a call to the `castIterableItem` method.
3 changes: 2 additions & 1 deletion docs/as-a-resource/wrapping.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,8 @@ UserData::from(User::first())->wrap('data');
A data collection inside a data object WILL get wrapped when a wrapping key is set:

```php
use Spatie\LaravelData\Attributes\DataCollectionOf;use Spatie\LaravelData\DataCollection;
use Spatie\LaravelData\Attributes\DataCollectionOf;
use Spatie\LaravelData\DataCollection;

class AlbumData extends Data
{
Expand Down

0 comments on commit c49ce35

Please sign in to comment.