Skip to content

Commit

Permalink
Merge branch 'main' into beyond-data
Browse files Browse the repository at this point in the history
# Conflicts:
#	CHANGELOG.md
  • Loading branch information
rubenvanassche committed Jul 6, 2023
2 parents 4d1176f + 90d43ee commit 83c46bf
Show file tree
Hide file tree
Showing 18 changed files with 808 additions and 283 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/dependabot-auto-merge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:

- name: Dependabot metadata
id: metadata
uses: dependabot/fetch-metadata@v1.5.1
uses: dependabot/fetch-metadata@v1.6.0
with:
github-token: "${{ secrets.GITHUB_TOKEN }}"

Expand Down
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ All notable changes to `laravel-data` will be documented in this file.
- Allow creating data objects using `from` without parameters
- Add support for a Dto and Resource object

## 3.7.0 - 2023-07-05

- Add support for better exception messages when parameters are missing
- Fix default properties generating validation rules when not provided
- Add last() method on DataCollection (#486)
- Add new manual written present attribute rule always overwrites a generated required rule
- Added the ability to create data files, casts, transformers and rules using Laravel Idea plugin #485

## 3.6.0 - 2023-06-02

- Add some config options to the `make:data` command (#449, #335)
Expand Down
2 changes: 1 addition & 1 deletion UPGRADING.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class SomeData extends Data {
}
```
- The type of `$rules` in the RuleInferrer handle method changed from `RulesCollection` to `PropertyRules`
- RuleInferrers now take a $context parameter which is a `ValidationCOntext` in their handle method
- RuleInferrers now take a $context parameter which is a `ValidationContext` in their handle method
- Validation attributes now keep track where they are being evaluated when you have nested data objects. Now field references are relative to the object and not to the root validated object
- Some resolvers are removed like: `DataClassValidationRulesResolver`, `DataPropertyValidationRulesResolver`
- The default order of rule inferrers has been changed
Expand Down
45 changes: 45 additions & 0 deletions docs/advanced-usage/commands.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
---
title: Commands
weight: 15
---

## make:data

You can easily generate new data objects with the artisan command `make:data`:

```shell
php artisan make:data PostData
```

By default, this command puts data objects in the `App\Data` namespace, this can be changed as such:

```shell
php artisan make:data PostData --namespace=DataTransferObjects
```

By default, the command creates a new data object within the `\App\Data` namespace and suffixes the class with `Data`, this can be changed by adding the following lines to the `data.php` config file:

```php
'commands' => [
/*
* Provides default configuration for the `make:data` command. These settings can be overridden with options
* passed directly to the `make:data` command for generating single Data classes, or if not set they will
* automatically fall back to these defaults. See `php artisan make:data --help` for more information
*/
'make' => [
/*
* The default namespace for generated Data classes. This exists under the application's root namespace,
* so the default 'Data` will end up as '\App\Data', and generated Data classes will be placed in the
* app/Data/ folder. Data classes can live anywhere, but this is where `make:data` will put them.
*/
'namespace' => 'DataTransferObjects',

/*
* This suffix will be appended to all data classes generated by make:data, so that they do are less likely
* to conflict with other related classes, controllers, or models with a similar name without resorting
* to adding an alias on to the end of the Data object. Set to a blank string (not null) to disable.
*/
'suffix' => 'DTO',
],
]
```
10 changes: 9 additions & 1 deletion docs/as-a-resource/wrapping.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Now the JSON looks like this:
}
```

Data objects will only get wrapped when you're sending them as a response and never when calling `toArray` or `toJson` on it.
Data objects and collections will only get wrapped when you're sending them as a response and never when calling `toArray` or `toJson` on it.

It is possible to define a default wrap key inside a data object:

Expand Down Expand Up @@ -212,3 +212,11 @@ Whenever a data object is wrapped due to the default wrap method or a global wra
```php
SongData::from(Song::first())->withoutWrapping();
```

## Getting a wrapped array

By default, `toArray` and `toJson` will never wrap a data object or collection, but it is possible to get a wrapped array:

```php
SongData::from(Song::first())->wrap('data')->transform(wrapExecutionType: WrapExecutionType::Enabled);
```
Loading

0 comments on commit 83c46bf

Please sign in to comment.