diff --git a/config/models.php b/config/models.php index 5f97d5bf..0ca42468 100644 --- a/config/models.php +++ b/config/models.php @@ -128,6 +128,7 @@ // 'soft_deletes' => [ // 'enabled' => true, // 'field' => 'deleted_at', + // 'field_as_string' => true, // ], /* diff --git a/src/Coders/Model/Model.php b/src/Coders/Model/Model.php index 25c03849..6f6bc7e5 100644 --- a/src/Coders/Model/Model.php +++ b/src/Coders/Model/Model.php @@ -112,6 +112,11 @@ class Model */ protected $DELETED_AT; + /** + * @var bool + */ + protected $softDeletesFieldAsString = true; + /** * @var bool */ @@ -193,6 +198,7 @@ protected function configure() // Soft deletes settings $this->withSoftDeletes($this->config('soft_deletes.enabled', $this->config('soft_deletes', false))); $this->withDeletedAtField($this->config('soft_deletes.field', $this->getDefaultDeletedAtField())); + $this->withSoftDeletesFieldAsString($this->config('soft_deletes.field_as_string', true)); // Connection settings $this->withConnection($this->config('connection', false)); @@ -255,8 +261,8 @@ protected function parseColumn(Fluent $column) $propertyName = $this->usesPropertyConstants() ? 'self::'.strtoupper($column->name) : $column->name; // Due to some casting problems when converting null to a Carbon instance, - // we are going to treat Soft Deletes field as string. - if ($column->name == $this->getDeletedAtField()) { + // by default, we are going to treat Soft Deletes field as string. + if ($column->name == $this->getDeletedAtField() && $this->softDeletesFieldAsString) { $cast = 'string'; } @@ -657,6 +663,18 @@ public function withDeletedAtField($field) return $this; } + /** + * @param string $field + * + * @return $this + */ + public function withSoftDeletesFieldAsString($softDeletesFieldAsString) + { + $this->softDeletesFieldAsString = $softDeletesFieldAsString; + + return $this; + } + /** * @return string */