dipherent's avatar

How to repopulate image field using the old() value helper?

Hi friends,

I have a form with a logo upload field. When validation fails, I can repopulate all the fields with the old() method, except for the image. How can I do this in Laravel? without using any JS validation.

please help me if you know how to do this.

I read somewhere that I can let the form process the image and then retrieve the same image from the db or from the session...

I appreciate your help,

Thanks

0 likes
3 replies
guybrush_threepwood's avatar

Hi @dipherent

You can't set an input file's value programatically due to security reasons.

You could try implementing the form using Livewire, which has support for file uploads, thus avoiding the need of repopulating the form and adding some interesting features such as background uploads, image previews, etc.

Frankly having to store the temporary upload in a session variable, making the validation conditional if such variable is set, having to hide de input if the file has already been uploaded, etc. seems like too much hassle for me.

Regards.

1 like

Please or to participate in this conversation.