-
Type: Question
-
Resolution: Fixed
-
Priority: Unknown
-
Affects Version/s: None
-
Component/s: Laravel
TimothyBJacobs has created Issue #2729: castAttribute does not handle nullable immutable date times in laravel-mongodb. This Jira ticket was filed by alcaeus
Issue Text:
- 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:
```php
if (is_null($value) && in_array($castType, static::$primitiveCastTypes))
```
Steps to reproduce
```php
class MyModel extends \MongoDB\Laravel\Eloquent\Model
$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.