S
S
Sergey delphinpro2021-09-08 09:37:59
Laravel
Sergey delphinpro, 2021-09-08 09:37:59

How to edit a form with uploaded files?

Let's say we have a form. Let the user profile.
In addition to other fields, there is a mandatory field for uploading files, such as an avatar, or some documents. Attaching files to a user is implemented through the morphToMany link.
There are no problems when filling out the form for the first time. Filled out, added files, the form was validated, everything is in a bunch.

The next step is to edit this form. There is no problem with regular fields, we fill them with values ​​from the model.
What about input[type=file]?You cannot add a value to it (the path to an already loaded file). In this case, you need to show the user that he already has a file uploaded. It is necessary to leave the opportunity to load a new one (replace, not add). And when saved, it must be validated if the user does not update the files.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
jazzus, 2021-09-08
@delphinpro

nullable for the field in validation and do not start the service to download the file if the file is not in the request. And the rest is decided at the front. You can show information that such and such a file is loaded or a picture and an empty file input next to it for replacement. there are a lot of front solutions you can peep somewhere and pick up closer to the task.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question