Skip to content

Commit 3dce9b9

Browse files
committed
Pass attribute key to object for reusability
1 parent 1edc6e7 commit 3dce9b9

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ protected function castToClass($key)
534534
return $this->classCastCache[$key];
535535
} else {
536536
return $this->classCastCache[$key] = forward_static_call(
537-
[$this->getCasts()[$key], 'fromModelAttributes'], $this, $this->attributes
537+
[$this->getCasts()[$key], 'fromModelAttributes'], $this->attributes, $key, $this
538538
);
539539
}
540540
}
@@ -565,7 +565,8 @@ protected function mergeAttributesFromClassCasts()
565565
{
566566
foreach ($this->classCastCache as $key => $value) {
567567
$this->attributes = array_merge(
568-
$this->attributes, $value->toModelAttributes($this, $this->attributes)
568+
$this->attributes,
569+
$value->toModelAttributes($this->attributes, $key, $this)
569570
);
570571
}
571572
}
@@ -640,7 +641,7 @@ protected function setClassCastableAttribute($key, $value)
640641
function () {
641642
return null;
642643
},
643-
$this->castToClass($key)->toModelAttributes($this)
644+
$this->castToClass($key)->toModelAttributes($this->attributes, $key, $this)
644645
));
645646

646647
unset($this->classCastCache[$key]);

tests/Database/DatabaseEloquentIntegrationTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1319,7 +1319,7 @@ public function __construct($lineOne, $lineTwo)
13191319
$this->lineTwo = $lineTwo;
13201320
}
13211321

1322-
public static function fromModelAttributes($model, $attributes)
1322+
public static function fromModelAttributes($attributes)
13231323
{
13241324
return new static($attributes['line_one'], $attributes['line_two']);
13251325
}

0 commit comments

Comments
 (0)