The error message "Call to a member function getClientOriginalName() on null" suggests that $this->file_name is null at the time when getClientOriginalName() is called. This could be due to the file not being properly uploaded or not being recognized by Livewire.
In Livewire, when you bind a file input with wire:model, it doesn't immediately set the property with the instance of the uploaded file. Instead, it sets the property with an instance of Livewire\TemporaryUploadedFile, which only gets resolved to an instance of Illuminate\Http\UploadedFile when you interact with it.
To ensure that the file is properly uploaded and recognized by Livewire, you can add a validation rule in your uploadFile method to check if the file is present before trying to interact with it. Here's how you can do it:
public function uploadFile($id) {
$this->validate([
'file_name' => 'required|file', // add this line
]);
// ... rest of your code
}
This will ensure that the file_name property is not null and is an instance of UploadedFile before you try to call getClientOriginalName() on it.
If the error persists, it might be due to a file size limit or a timeout issue on your server. Check your PHP and server configuration to ensure that they can handle the size of the files you're trying to upload.