Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

quickee's avatar

Dispatching Data from Javascript to LW component

My goal is to dispatch an array from a script - into a livewire component. I have a select2 im working with wire:model is not playing nice.

If I dd($values) inside the component - that works and I can see the data. But if I try to remove the dd() and do something else with the variable. I get this error.

Unable to resolve dependency [Parameter #0 [ <required> $values]] in class App\Livewire\Foo

script.js

   document.addEventListener('save', (event)=>{
        Livewire.dispatch('save',{values:"testing"});
    })

livewire component

class Foo extends Component
{

  protected $listeners = ['save'];
    public function save($values)
    {
         dd($value);
        return false;
    }
}

0 likes
0 replies

Please or to participate in this conversation.