Skip to content

Commit

Permalink
Fixed casting bug
Browse files Browse the repository at this point in the history
  • Loading branch information
vahidRP committed Jun 16, 2020
1 parent 3101532 commit 450f288
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/PersianDate.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ class PersianDate extends Field
public function __construct($name, $attribute = null, $resolveCallback = null)
{
parent::__construct($name, $attribute, $resolveCallback ?? function ($value) {
if (! $value instanceof DateTimeInterface) {
if (!is_null($value) && ! $value instanceof DateTimeInterface) {
throw new Exception("Date field must cast to 'date' in Eloquent model.");
}

return $value->format('Y-m-d');
return is_null($value) ? $value : $value->format('Y-m-d');
});
}

Expand Down
2 changes: 1 addition & 1 deletion src/PersianDateTime.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function __construct($name, $attribute = null, $resolveCallback = null)
{
$this->meta['format'] = $this->meta['format'] ?? 'YYYY-MM-DD HH:mm:ss';
parent::__construct($name, $attribute, $resolveCallback ?? function ($value) {
if (! $value instanceof DateTimeInterface) {
if (!is_null($value) && ! $value instanceof DateTimeInterface) {
throw new Exception("DateTime field must cast to 'datetime' in Eloquent model.");
}

Expand Down

0 comments on commit 450f288

Please sign in to comment.