Skip to content

Commit a6b3868

Browse files
authored
[8.x] Fix attribute casting (#40245)
* Add failing test * Fix attribute casting issue * Update DatabaseEloquentModelAttributeCastingTest.php
1 parent a67bdd3 commit a6b3868

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -571,8 +571,7 @@ public function hasAttributeGetMutator($key)
571571

572572
return static::$attributeMutatorCache[get_class($this)][$key] = $returnType &&
573573
$returnType instanceof ReflectionNamedType &&
574-
$returnType->getName() === Attribute::class &&
575-
is_callable($this->{$method}()->get);
574+
$returnType->getName() === Attribute::class;
576575
}
577576

578577
/**
@@ -949,8 +948,7 @@ public function hasAttributeSetMutator($key)
949948

950949
return static::$setAttributeMutatorCache[$class][$key] = $returnType &&
951950
$returnType instanceof ReflectionNamedType &&
952-
$returnType->getName() === Attribute::class &&
953-
is_callable($this->{$method}()->set);
951+
$returnType->getName() === Attribute::class;
954952
}
955953

956954
/**

tests/Integration/Database/DatabaseEloquentModelAttributeCastingTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,8 @@ public function testOneWayCasting()
142142
{
143143
$model = new TestEloquentModelWithAttributeCast;
144144

145+
$this->assertNull($model->password);
146+
145147
$model->password = 'secret';
146148

147149
$this->assertEquals(hash('sha256', 'secret'), $model->password);

0 commit comments

Comments
 (0)