Skip to content

Commit

Permalink
Merge pull request #8870 from kenjis/fix-DataCaster-nullable
Browse files Browse the repository at this point in the history
fix: [Model] casting may throw InvalidArgumentException: Invalid parameter: nullable
  • Loading branch information
kenjis authored May 10, 2024
2 parents fd0a3b6 + 79ad7f1 commit e68553f
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion system/DataCaster/DataCaster.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public function castAs(mixed $value, string $field, string $method = 'get'): mix
$params = array_map('trim', explode(',', $matches[2]));
}

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

Expand Down
4 changes: 2 additions & 2 deletions tests/_support/Models/UserCastsTimestampModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ class UserCastsTimestampModel extends Model
'id' => 'int',
'name' => 'base64',
'email' => 'json-array',
'created_at' => 'datetime',
'updated_at' => 'datetime',
'created_at' => '?datetime',
'updated_at' => '?datetime',
];
protected array $castHandlers = [
'base64' => CastBase64::class,
Expand Down

0 comments on commit e68553f

Please sign in to comment.