diff --git a/src/Eloquent/Model.php b/src/Eloquent/Model.php index 3553e02ab..03c77c239 100644 --- a/src/Eloquent/Model.php +++ b/src/Eloquent/Model.php @@ -216,7 +216,9 @@ public function attributesToArray() // Convert dot-notation dates. foreach ($this->getDates() as $key) { if (Str::contains($key, '.') && Arr::has($attributes, $key)) { - Arr::set($attributes, $key, (string) $this->asDateTime(Arr::get($attributes, $key))); + Arr::set($attributes, $key, $this->serializeDate( + $this->asDateTime(Arr::get($attributes, $key)) + )); } } diff --git a/tests/ModelTest.php b/tests/ModelTest.php index 75723c1cb..2f43e72b0 100644 --- a/tests/ModelTest.php +++ b/tests/ModelTest.php @@ -577,7 +577,7 @@ public function testDates(): void $data = $user->toArray(); $this->assertNotInstanceOf(UTCDateTime::class, $data['entry']['date']); - $this->assertEquals((string) $user->getAttribute('entry.date')->format('Y-m-d H:i:s'), $data['entry']['date']); + $this->assertEquals($user->getAttribute('entry.date')->format('l jS \of F Y h:i:s A'), $data['entry']['date']); } public function testCarbonDateMockingWorks()