I have a very basic Livewire component. I know, there is a wire:click, but I simplified it very much, to give you something by hand. In my real app, there is a calendar component and when you click on an event, it fires the emit() and sends data from the ui to the Livewire component, where it get’s modified.
My question is: How can post this data from the Livewire component to the foo.store route?
app/Http/Livewire/Foo.php:
class Foo extends Component
{
public $foo;
protected $listeners = [
'store' => 'store'
];
public function render()
{
return view('livewire.foo');
}
public function store($data)
{
$payload = $this->do_complex_math_on_data($data);
// ❓ post payload to FooController's store() function - HOW?
}
private function do_complex_math_on_data($data)
{
return 1+1;
}
}
resources/views/livewire/foo.blade.php:
<div>
<button>Click me!</button>
</div>
<script>
document.addEventListener('livewire:load', function() {
document.querySelector('button').addEventListener('click' () => {
Livewire.emit('store', data.coming.from.ui);
});
});
</script>