Skip to content

Commit

Permalink
PR cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenvanassche committed Jan 23, 2025
1 parent bd7b609 commit c88ecb7
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
---
title: Available mappers
title: Available property mappers
weight: 19
---

Sometimes the property names in the array from which you're creating a data object might be different.
You can use mappers for property names when it is created from an array using attributes:
In previous sections we've already seen how
to [create](/docs/laravel-data/v4/as-a-data-transfer-object/mapping-property-names) data objects where the keys of the
payload differ from the property names of the data object. It is also possible
to [transform](/docs/laravel-data/v4/as-a-resource/mapping-property-names) data objects to an
array/json/... where the keys of the payload differ from the property names of the data object.

These mappings can be set manually put the package also provide a set of mappers that can be used to automatically map
property names:

```php
class ContractData extends Data
Expand Down Expand Up @@ -39,3 +45,16 @@ ContractData::from([
'ADDRESSLINE2' => 'some address line 2',
]);
```

When transforming such a data object the payload will look like this:

```json
{
"name" : "Rick Astley",
"record_company" : "RCA Records",
"country field" : "Belgium",
"CityName" : "Antwerp",
"addressline1" : "some address line 1",
"ADDRESSLINE2" : "some address line 2"
}
```
2 changes: 1 addition & 1 deletion docs/as-a-data-transfer-object/mapping-property-names.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,4 @@ SongData::from([
]);
```

You can also use other mappers to input and output property name mapping (see [available mappers](/docs/laravel-data/v4/advanced-usage/available-mappers)).
The package has a set of default mappers available, you can find them [here](/docs/laravel-data/v4/advanced-usage/available-property-mappers).
2 changes: 1 addition & 1 deletion docs/as-a-resource/mapping-property-names.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,4 @@ And a transformed version of the data object will look like this:
]
```

You can also use other mappers to input and output property name mapping (see [available mappers](/docs/laravel-data/v4/advanced-usage/available-mappers)).
The package has a set of default mappers available, you can find them [here](/docs/laravel-data/v4/advanced-usage/available-property-mappers).

0 comments on commit c88ecb7

Please sign in to comment.