FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

unify behavior of toArray when dates are in casts and date arrays." · JavaDevl/framework@2298bf0 · GitHub

Commit 2298bf0

Browse files
committed
unify behavior of toArray when dates are in casts and date arrays."
1 parent a38e420 commit 2298bf0

2 files changed

Lines changed: 6 additions & 4 deletions

File tree

‎src/Illuminate/Database/Eloquent/Model.php‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2522,6 +2522,10 @@ public function attributesToArray()
25222522
$attributes[$key] = $this->castAttribute(
25232523
$key, $attributes[$key]
25242524
);
2525+
2526+
if ($attributes[$key] && ($value === 'date' || $value === 'datetime')) {
2527+
$attributes[$key] = $this->serializeDate($attributes[$key]);
2528+
}
25252529
}
25262530

25272531
// Here we will grab all of the appended, calculated attributes to this model

‎tests/Database/DatabaseEloquentModelTest.php‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1210,10 +1210,8 @@ public function testModelAttributesAreCastedWhenPresentInCastsArray()
12101210
$this->assertEquals($obj, $arr['objectAttribute']);
12111211
$this->assertEquals(['foo' => 'bar'], $arr['arrayAttribute']);
12121212
$this->assertEquals(['foo' => 'bar'], $arr['jsonAttribute']);
1213-
$this->assertInstanceOf('Carbon\Carbon', $arr['dateAttribute']);
1214-
$this->assertInstanceOf('Carbon\Carbon', $arr['datetimeAttribute']);
1215-
$this->assertEquals('1969-07-20', $arr['dateAttribute']->toDateString());
1216-
$this->assertEquals('1969-07-20 22:56:00', $arr['datetimeAttribute']->toDateTimeString());
1213+
$this->assertEquals('1969-07-20 00:00:00', $arr['dateAttribute']);
1214+
$this->assertEquals('1969-07-20 22:56:00', $arr['datetimeAttribute']);
12171215
$this->assertEquals(-14173440, $arr['timestampAttribute']);
12181216
}
12191217

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL