Skip to content

Commit ef37df1

Browse files
committed
if null, default to empty string
1 parent 133d543 commit ef37df1

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

resources/lang/en/messages.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22

33
return [
4+
'must-be-string' => ':Attribute must be a string or null',
45
'error-message' => 'JSON validaton failed for :attribute.',
56
'detailed-error-message' => 'JSON validation failed for :attribute. :details',
67
];

src/Rules/BaseRule.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@ public function __construct(
2727
*/
2828
public function validate(string $attribute, mixed $value, Closure $fail): void
2929
{
30+
$value ??= '';
31+
32+
if (! is_string($value)) {
33+
$fail('json-schema::messages.must-be-string')->translate(['attribute' => $attribute]);
34+
}
35+
3036
$result = $this->schemaValidator->validate($this->determineSchemaName(), $value);
3137

3238
if ($result->failed()) {

0 commit comments

Comments
 (0)