Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

castAttribute does not handle nullable immutable date times #2729

Closed
TimothyBJacobs opened this issue Feb 18, 2024 · 0 comments
Closed

castAttribute does not handle nullable immutable date times #2729

TimothyBJacobs opened this issue Feb 18, 2024 · 0 comments

Comments

@TimothyBJacobs
Copy link

  • Laravel-mongodb Version: 4.1.1
  • PHP Version: 8.1
  • Database Driver & Version: 6.0.13

Description:

The castAttribute method is overloaded in the base Model class. Unlike in the Core Laravel hasAttributes trait, it is missing handling for null values. See this code snippet from Laravel:

if (is_null($value) && in_array($castType, static::$primitiveCastTypes)) {
    return $value;
}

Steps to reproduce

class MyModel extends \MongoDB\Laravel\Eloquent\Model {
    protected $casts = [
        'my_date' => 'immutable_datetime',
    ];
}

$model = new MyModel();
$model->my_date; // Should be null, instead is current time.

Expected behaviour

null should be returned.

Actual behaviour

The current time is returned.

# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

No branches or pull requests

2 participants