Skip to content

Commit

Permalink
add datetime format as well
Browse files Browse the repository at this point in the history
  • Loading branch information
themsaid committed Feb 1, 2018
1 parent a4b23b8 commit f8abc3f
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ protected function addCastAttributesToArray(array $attributes, array $mutatedAtt
$attributes[$key] = $this->serializeDate($attributes[$key]);
}

if ($attributes[$key] && Str::startsWith($value, 'date:')) {
if ($attributes[$key] && Str::startsWith($value, ['date:', 'datetime:'])) {
$attributes[$key] = $attributes[$key]->format(explode(':', $value, 2)[1]);
}
}
Expand Down Expand Up @@ -509,7 +509,7 @@ protected function castAttribute($key, $value)
*/
protected function getCastType($key)
{
if (Str::startsWith($this->getCasts()[$key], 'date:')) {
if (Str::startsWith($this->getCasts()[$key], ['date:', 'datetime:'])) {
return 'custom_datetime';
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,6 @@ class TestModel1 extends Model

public $casts = [
'date_field' => 'date:Y-m',
'datetime_field' => 'date:Y-m H:i',
'datetime_field' => 'datetime:Y-m H:i',
];
}

0 comments on commit f8abc3f

Please sign in to comment.