From 06214c618e4531c4965b4e0356d073c77d5aa9e9 Mon Sep 17 00:00:00 2001 From: Alexander Smetanenko <alex.smko@outlook.com> Date: Wed, 9 Jun 2021 23:33:08 +0700 Subject: [PATCH] Fix nested dates format --- src/Eloquent/Model.php | 4 +++- tests/ModelTest.php | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) 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()