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

amir5's avatar
Level 7

How to dispatch events to specific component id

How to dispatch events to specific component id? Currently I have the target component id, and I can dispatch event to it e.g, ->dispatch('set-value-'.$this->dispatchToId), but I can't listen to that event specifically in target component.

I've read Listening for dynamic event names in livewire docs but It can't do that:

    #[On('set-values-{__id}')] // ERROR: Unable to evaluate dynamic event name placeholder: {__id}
	public function setValues() {}}
0 likes
7 replies
Sinnbeck's avatar

Can you show the full component where you want to listen?

Also you are dispatching set-value but listening to set-values (with an s at the end)

amir5's avatar
Level 7

@Sinnbeck The problem is, when I try to generate dynamic listen names like: #[On('set-values-{__id}')] livewire throws exception: Unable to evaluate dynamic event name placeholder: {__id}

tykus's avatar

@amir5 define a property on the Component to grab the __id

public $__id;


#[On('set-values-{__id}')]
public function setValues()
{
    // ...
}
Sinnbeck's avatar

@amir5 Yes you said that already but without seeing the component I cannot see the issue. I guess you forgot to add the property as @tykus suggested, but its impossible to know without seeing your code..

amir5's avatar
Level 7

@tykus livewire class has a property called __id that holds component id, and I want to use that.

Sinnbeck's avatar

@amir5 Well that obviously does not work. But I assume you are passing in the ID or the model that you can use instead? :) The __ most likely refers to it being an internal value

tykus's avatar

@amir5 then find some other property to target the Component; like @sinnbeck says, we're seeing only a snippet of your work and cannot guess at what you are working with.

Please or to participate in this conversation.