diff --git a/src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php b/src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php index 07ba3b0bdfce..64e84e2e403a 100644 --- a/src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php +++ b/src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php @@ -1070,6 +1070,8 @@ protected function setAttributeMarkedMutatedAttributeValue($key, $value) } else { unset($this->attributeCastCache[$key]); } + + return $this; } /** diff --git a/tests/Integration/Database/DatabaseEloquentModelAttributeCastingTest.php b/tests/Integration/Database/DatabaseEloquentModelAttributeCastingTest.php index e3e8da8f4c99..a6263a096e91 100644 --- a/tests/Integration/Database/DatabaseEloquentModelAttributeCastingTest.php +++ b/tests/Integration/Database/DatabaseEloquentModelAttributeCastingTest.php @@ -47,6 +47,10 @@ public function testBasicCustomCasting() $this->assertSame('DRIES', $model->uppercase); + $model = $model->setAttribute('uppercase', 'james'); + + $this->assertInstanceOf(TestEloquentModelWithAttributeCast::class, $model); + $model = new TestEloquentModelWithAttributeCast; $model->address = $address = new AttributeCastAddress('110 Kingsbrook St.', 'My Childhood House');