vincent15000's avatar

Upload problem after upgrading from Livewire 2 to Livewire 3

Hello,

I get this error when I click on the upload button.

> wire-wildcard.js:22 Alpine Expression Error: Cannot read properties of undefined (reading 'name') Expression: "$wire.upload"

The error comes from the supportFileUploads.js file.

Any idea on what I could do ?

Thanks for your help ;).

V

0 likes
8 replies
Tray2's avatar

I would suggest reading the upgrade guide, it will likely have that issue covered.

Without more code it's hard to say, but there was a change made between version 2 and 3, regarding how you set the model, in version 2 you could do the whole form, but in version 3 you need to set the model on each input.

1 like
vincent15000's avatar

I have followed the upgrade guide to process this upgrade, but you are right, I probably missed a paragraph about the upload.

I will read the upgrade guide once again.

Thank you ;).

vincent15000's avatar

However I set the 'legacy_model_binding configuration key to true.

vincent15000's avatar

I think that I didn't check in the right direction.

The upload() seems to not be executed.

<form class="space-y-4 @if ($nombreRestant == 0) hidden @endif" wire:submit.prevent="upload">
public function upload()
{
    dd('ok');
}

I don't see any ok on the screen when I click on the submit button.

vincent15000's avatar

@rihulfaakbar @tray2

Ok it's solved.

My upload function was named upload().

I just renamed it to uploadFile() and it works fine.

I really don't know why it's not possible to use this name ... would it be now a reserved keyword for Livewire ?

Tray2's avatar
Tray2
Best Answer
Level 73

Apparently it is a reserved word in livewire,

In Livewire 3, naming a method upload in your component is a "gotcha" that causes issues because "upload" is a reserved word used internally by Livewire for handling file uploads. Laravel Livewire Laravel Livewire Using upload as a method name conflicts with Livewire's JavaScript-to-server communication, preventing your component from properly storing files or receiving them as null. The Core Issue Reserved Method/Property: You cannot use upload as a method or property name in your Livewire component class. Why it fails: When a file is selected, Livewire's JS makes a request to a temporary "signed" URL. If you have a method named upload, it clashes with this process. Common Error: The wire:submit or wire:click does not trigger the method, or the file input behaves unexpectedly. Laracasts Laracasts +4 How to Fix It Rename your upload() method to something else, such as save(), submit(), or store().

1 like
Tray2's avatar

In the beginning there is a notice about upload being reserved. Odd that they haven't fixed the example.

1 like

Please or to participate in this conversation.