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

Commit 4c0ec01

Browse files
committed
allow executing something on failed assignment
1 parent 047c8de commit 4c0ec01

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/Traits/WithModelMapping.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@ trait WithModelMapping
1111
/**
1212
* Maps your model attributes to local class properties.
1313
*
14-
* @param Model|null $model
14+
* @param Model|null $model
15+
* @param \Closure|null $failure
1516
*
1617
* @return void
1718
*/
18-
public function mapModelAttributes(?Model $model = null): void
19+
public function mapModelAttributes(?Model $model = null, ?\Closure $failure = null): void
1920
{
2021
if (! is_null($model)) {
2122
$toIgnore = config('model-mapper.ignore_attributes');
@@ -26,11 +27,11 @@ public function mapModelAttributes(?Model $model = null): void
2627

2728
collect($model->getAttributes())
2829
->except($ignores)
29-
->each(function ($value, $property) use ($model) {
30+
->each(function ($value, $property) use ($model, $failure) {
3031
if (property_exists($this, $property)) {
3132
rescue(
3233
fn () => $this->{$property} = $model->{$property},
33-
fn () => null,
34+
$failure,
3435
config('model-mapper.log') ?? false
3536
);
3637
}

0 commit comments

Comments
 (0)