Closed
Description
- 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.