Skip to content

Exception when using CarbonImmutable #3341

Closed
@saineshmamgain

Description

@saineshmamgain
  • Laravel-mongodb Version: 5.2.2
  • PHP Version: 8.2.28
  • Database Driver & Version:

Description:

Steps to reproduce

  1. Add Date::use(CarbonImmutable::class); in your AppServiceProvider's boot method.

Expected behaviour

There should not be any exception

Actual behaviour

An exception occurs with the message:
MongoDB\\Laravel\\Eloquent\\Model::asDateTime(): Return value must be of type Carbon\\Carbon, Carbon\\CarbonImmutable returned

This can be solved if we change the return type of asDateTime to CarbonInterface or DateTimeInterface.

Logs:
{
    "message": "MongoDB\\Laravel\\Eloquent\\Model::asDateTime(): Return value must be of type Carbon\\Carbon, Carbon\\CarbonImmutable returned",
    "exception": "TypeError",
    "file": "/var/www/html/sg-ui-backend/vendor/mongodb/laravel-mongodb/src/Eloquent/DocumentModel.php",
    "line": 136
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions