Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

seedphrase's avatar

Update File upload

Hey,

When I submit the form for update, it doesn't work because of the file, it doesn't find the file. I am using laravel inertia and vue. This is my form

const form = useForm({
    foo: props.object.foo,
    bar: props.object.bar,
    file_upload: null,
});
    <form
            @submit.prevent="form.post(route('update', object), {
                _method: 'put',
                file_upload: form.file_upload,
                forceFormData: true,
            })"
      
0 likes
4 replies
jlrdw's avatar

Use file system to delete the file and replace it.

seedphrase's avatar

@jlrdw Yes I did it. If the user deletes the file and then uploads an other, everything goes okay. But if the user wants to update some informations without replacing the file, this is my problem...

Snapey's avatar

@@foobar Why would this problem be with the view code? Surely the issue lays in the controller?

seedphrase's avatar

@Snapey this is from the controller the update methode

   if (request()->hasFile('file_upload')) {
   $document = resolve(StoreDocument::class)->execute($object, request()->file('file_upload'));

 resolve(UploadDocumentFromFileContentAction::class)->execute($document, request()->file('file_upload')->getContent());
}

This is the uploadDocumentFromFileContentAction

class UploadDocumentFromFileContentAction
{
    public function execute(Document $document, string $fileContent): void
    {
        throw_unless(
            Storage::put($document->path . $document->file_name, $fileContent),
            Exception::class,
            'The file ' . $document->file_name . ' can not be stored in cloud.'
        );
    }

Please or to participate in this conversation.