Search code examples
phplaravellaravel-livewire

Livewire multiple issues with file upload


What seems to be the problem:

6 exceptions being logged with each upload (although the file gets uploaded)

Steps to Reproduce:

  1. Follow the documentation page to create simple file upload
  2. Try uploading a file
  3. Check laravel log file

Laravel version: 5.7

Livewire version: 1.3.5

Laravel log sample:

[2021-01-21 11:05:07] local.ERROR:  {"userId":47,"email":"[email protected]","exception":"[object] (Exception(code: 0):  at /home/ameer/public_html/livewire.local/vendor/livewire/livewire/src/ComponentConcerns/HandlesActions.php:114)
[stacktrace]
#0 /home/ameer/public_html/livewire.local/vendor/laravel/framework/src/Illuminate/Foundation/helpers.php(755): Livewire\\Component->Livewire\\ComponentConcerns\\{closure}()
#1 /home/ameer/public_html/livewire.local/vendor/livewire/livewire/src/ComponentConcerns/HandlesActions.php(121): rescue(Object(Closure), Object(Closure), false)
#2 [internal function]: Livewire\\Component->Livewire\\ComponentConcerns\\{closure}(Object(ReflectionParameter), 0)
#3 /home/ameer/public_html/livewire.local/vendor/laravel/framework/src/Illuminate/Support/Collection.php(1034): array_map(Object(Closure), Array, Array)
#4 /home/ameer/public_html/livewire.local/vendor/livewire/livewire/src/ComponentConcerns/HandlesActions.php(122): Illuminate\\Support\\Collection->map(Object(Closure))
#5 /home/ameer/public_html/livewire.local/vendor/livewire/livewire/src/ComponentConcerns/HandlesActions.php(99): Livewire\\Component->resolveActionParameters('startUpload', Array)
#6 /home/ameer/public_html/livewire.local/vendor/livewire/livewire/src/Connection/ConnectionHandler.php(46): Livewire\\Component->callMethod('startUpload', Array)
...

Solution

  • After some debugging I found that the exception is caused by line #111 in vendor/livewire/livewire/src/ComponentConcerns/HandlesActions.php

    I was able to work around the issue by overriding the resolveActionParameters method from the livewire component file.

    Changed the method to simply return a collection of $params

    protected function resolveActionParameters($method, $params)
    {
        return collect($params);
    }
    

    So far this has prevented the excesive logging of exceptions and didn't break any livewire functionality.