- Could you paste your php.ini values for
upload_max_filesize&post_max_sizeand also answer how big was the test file you are uploading? - What do you get when you add this:
public function updatedSanmarFile()
{
Log::info('File has been updated:', ['sanmar_file' => $this->sanmar_file]);
}
It seems like there are events that you dispatch, and you should keep in mind that events in Livewire are asynchronous. This means that when you upload a file and then try to do some other action with that file, the file might not be fully uploaded yet, resulting in it being null.
I had a similar issue. If you need your actions to be synchronous (execute one after another), you should split your code into smaller functions and parts that can be called via events, ensuring they execute in the correct order. The dispatch() call should be the last thing in those functions.
Here's how I've been handling it:
- Split the Code: Break down your logic into smaller methods.
- Chain Events: Use events to chain these methods together in the correct sequence.
- Ensure Order: Make sure the file upload completes before triggering any subsequent actions. Here's an example of how I handled a similar issue: Dealing with Livewire 3's Async Event Communication Between Components. The solution was: Breaking my code into smaller parts and ensuring events were called in sequence.
----------------------------------------------------
- Another possibility is that you could use updatedSanmarFile() to handle the logic, because it would be called after the variable for the file upload has been changed. Note that this isn't called after the file has been fully uploaded, but when the binding variable for it was.
- You could add indicators to see when the file was uploaded and when it finishes...I just realized those events are triggering changes in the front-end, I figured they were going into another Livewire Compoenent. Do your indicators work, because you have
wire:target="uploadSanmarDataLibraryToDatabase"?
<div wire:loading wire:target="sanmar_file" class="mt-3 text-blue-500">
Uploading...
</div>
<div wire:loading.remove wire:target="sanmar_file" class="mt-3 text-green-500">
Upload complete.
</div>