Skip to content
This repository was archived by the owner on Mar 12, 2024. It is now read-only.

Commit 5d0786d

Browse files
committed
make ignored attributes configurable
1 parent cbd8d3d commit 5d0786d

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

config/model-mapper.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,12 @@
1313

1414
'log' => true,
1515

16+
/*
17+
|
18+
| Determine if you want to log failed assignments.
19+
|
20+
*/
21+
22+
'ignore_attributes' => ['id', 'password'],
23+
1624
];

src/Traits/WithModelMapping.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,14 @@ trait WithModelMapping
1818
public function mapModelAttributes(?Model $model = null): void
1919
{
2020
if (! is_null($model)) {
21+
$toIgnore = config('model-mapper.ignore_attributes');
22+
23+
$ignores = is_array($toIgnore)
24+
? $toIgnore
25+
: [];
26+
2127
collect($model->getAttributes())
22-
->except('id', 'password')
28+
->except(...$ignores)
2329
->each(function ($value, $property) use ($model) {
2430
if (property_exists($this, $property)) {
2531
rescue(

0 commit comments

Comments
 (0)