dan3460's avatar

syncInput doesn't exists

I'm following an quick tutorial to upload multiple files using Livewire by sinnbeck.dev that calls for, in the livewire component:

$this->syncInput($name,$files);

i'm getting a:

Method App\Livewire\Uploads\FileUpload::syncInput does not exist.

He is using the finishUpload function to bring the files to a temporary folder. I'm guessing the function synchronizes the file names in the front end? Using Livewire 3.0

0 likes
1 reply
LaryAI's avatar
Level 58

It seems like you're encountering an issue because the syncInput method does not exist in Livewire. This could be due to a change in the Livewire API or a custom method that was not defined in the tutorial you are following.

In Livewire, to handle file uploads, you typically use the $this->emit method to emit an event or the wire:model directive to bind file inputs to a component property. Here's how you can handle multiple file uploads with Livewire:

  1. In your Livewire component, define a property to hold the uploaded files:
use Livewire\Component;
use Livewire\WithFileUploads;

class FileUpload extends Component
{
    use WithFileUploads;

    public $files = [];

    public function uploadFiles()
    {
        // Handle the file upload process here
        foreach ($this->files as $file) {
            // Save each file or process it
        }

        // Clear the file input
        $this->files = [];
    }

    public function render()
    {
        return view('livewire.file-upload');
    }
}
  1. In your Livewire view file (e.g., file-upload.blade.php), use the wire:model directive to bind the file input to the $files property:
<form wire:submit.prevent="uploadFiles">
    <input type="file" wire:model="files" multiple>

    @error('files.*') <span class="error">{{ $message }}</span> @enderror

    <button type="submit">Upload</button>
</form>
  1. When the form is submitted, the uploadFiles method will be called, and you can handle the uploaded files as needed.

If you need to move the files to a temporary folder, you can do so within the uploadFiles method. Livewire automatically stores uploaded files in a temporary directory, and you can access them through the $this->files array.

Remember to include the WithFileUploads trait in your Livewire component to handle file uploads properly.

If the tutorial you are following is using a custom method like syncInput, you might need to reach out to the author for clarification or check if there's an updated version of the tutorial that is compatible with Livewire 3.0.

Please or to participate in this conversation.