Optional doesn't work well with null #161
Replies: 1 comment 1 reply
-
I took a quick peek on this. It's definitely possible that I've missed the Depending on what you'd like to achieve, you could possibly use the Exclude rules to remove the attribute from the data, if the value is null. public static function rules(array $payload): array
{
return [
'content' => [Rule::excludeIf(! isset($payload['content']))],
];
} as outlined in the Laravel documentation. Also of note, you may need to also add the Edit: So I don't forget - you may also set $data['content'] ??= Optional::create();
Data::from($data); But I'm not sure that'd actually help with the validation. |
Beta Was this translation helpful? Give feedback.
-
Payload (request):
Data object:
Results in invalid data error. Is this intended? A workaround is to use
public Optional|string|null $content
or to filter null values out of the payload.Beta Was this translation helpful? Give feedback.
All reactions