Karlis's avatar

How to pass parameter to Livewire event from template

The documentation gives an example that an event can be emitted from a template

<button wire:click="$emit('postAdded')">

or from component

$this->emit('postAdded');

Later it states that parameters can be passed but only gives example from component

$this->emit('postAdded', $post->id);

How can I achieve the same from a template? I've managed to pass hardcoded values

<button wire:click="$emit('postAdded', 'hardcoded-value')">

but I'd want it to be coming from wire:model.

0 likes
2 replies
AamirSohailKmAs's avatar

Coming From wire:model mean? wire:model is binding between component's class property and frontend, so in this way you can access it within the class and emit using this example,

$this->emit('postAdded', $post->id);

pysosu's avatar

In your button put the dynamic data in single quotes like you will pass a hard-coded-value.

Example: '{{$post->id}}

That worked for me.

1 like

Please or to participate in this conversation.