Skip to content

Question/Error when a date is null #1458

Open
@mattdalmau

Description

@mattdalmau

Hello -

I'm facing an issue when the value of a date is null instead of being a date. I understand that value 'null' should not be stored as date in mongodb but it happens.
As a workaround I have implemented this small change in Eloquent/Model.php (l.98)

    /**
     * @inheritdoc
     */
    protected function asDateTime($value)
    {
        // Convert UTCDateTime instances.
        if ($value instanceof UTCDateTime) {
            return Carbon::createFromTimestamp($value->toDateTime()->getTimestamp());
        }
        if (isset($value)){
            return parent::asDateTime($value);
        }
        return '';
    }

Is there a better way to address this issue?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions