GizaRex's avatar

Laravel 10 Form request validation image

Maybe this will be an stupid question. But when I want to validate an nullable image I don't get anything. This is in my FormRequest

            'image' => 'nullable|image',

So when I upload an image I get an UploadeFile what I expect. But when I don't upload an file, I don't get nothing. The value image is not in the $validated in my controller. But I expect an null value. What did I do wrong?

0 likes
6 replies
vincent15000's avatar

Isn't that logic that you don't get a file if you don't upload any ?

Snapey's avatar

not sure why you expect different?

1 like
GizaRex's avatar

So when I do it for example with an text field like this

'retentiontime' => 'nullable|string',

When I submit the form I get in the validated request an null value for retentiontime. But for an image It is nothing. Or is it just not possible for an image

1 like
Snapey's avatar

@GizaRex is an uploaded image in the request data (before validation), coming from the browser?

1 like
GizaRex's avatar

@Snapey If I there is an image uploaded, then there is an image before validation. If I don't upload an image, then there is totally nothing of an value for image before validation

1 like
Snapey's avatar

@GizaRex therefore you don't get an entry in validated data because you have said its nullable

1 like

Please or to participate in this conversation.