Skip to content

Commit e68553f

Browse files
authored
Merge pull request #8870 from kenjis/fix-DataCaster-nullable
fix: [Model] casting may throw InvalidArgumentException: Invalid parameter: nullable
2 parents fd0a3b6 + 79ad7f1 commit e68553f

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

system/DataCaster/DataCaster.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ public function castAs(mixed $value, string $field, string $method = 'get'): mix
159159
$params = array_map('trim', explode(',', $matches[2]));
160160
}
161161

162-
if ($isNullable) {
162+
if ($isNullable && ! $this->strict) {
163163
$params[] = 'nullable';
164164
}
165165

tests/_support/Models/UserCastsTimestampModel.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ class UserCastsTimestampModel extends Model
2828
'id' => 'int',
2929
'name' => 'base64',
3030
'email' => 'json-array',
31-
'created_at' => 'datetime',
32-
'updated_at' => 'datetime',
31+
'created_at' => '?datetime',
32+
'updated_at' => '?datetime',
3333
];
3434
protected array $castHandlers = [
3535
'base64' => CastBase64::class,

0 commit comments

Comments
 (0)