File upload behaviour differs from other fields

I have already checked other topics but none of them fits this issue.

I have a Model. On creation of this model, I can upload a file with it (jpg or png).

Even though this is not necessary, I have had to make it necessary (skipOnEmpty => false), otherwise model->save() fails.

But the problem is, that because it is necessary, if the user enters and wants to modify some data, they must upload the image again. The other fields are filled with whatever their data is in DB. But the file field is empty.

I have read that this is a behaviour of the file because it is different from other fields, something about the file being stored in a temporary area. But how could I fix this then? It is ok that on creation, file is required and won’t let the user be created without this image, but on update, this already exists. Am I doing something wrong with the file?

Also, though I am not 100% sure still, but modifying the Model is not working, I am suspecting because of the same issue? By modifying, I mean searching the model by its ID and changing any data.

Any help is appreciated.

Hi maxkoa, one way to solve this is by using Model Scenarios.

For the file field set one validation for the creation and another for the update.

1 Like

thank you! didn’t know this existed