Why events can not accept other than integer ID parameters in events?

Am working with shopping cart, trying to pass $item->rowId as parameter in an event like this
wire:click="$emit(‘removeItem’, {{ $item->rowId }})"
and in my console I get this error
VM205:6 Uncaught SyntaxError: Invalid or unexpected token
at Directive.parseOutMethodAndParams (wire-directives.js:93)

But when I try to pass any integer as parameter is working good

rowId = 027c91341fd5cf4d2579b49c4b6a90da

Any trick please to solve my problem

I think, dont use blade tags

wire:click="$emit(‘removeItem’, $item->rowId)"

View in the browser source to verify the event code.

1 Like

Take a look at Emit an event in the documentation

1 Like

This is a pure javascript and you have to quote the string:
wire:click="$emit(‘removeItem’, '{{ $item->rowId }}' )"

More universal option is to use JSON encode:
wire:click="$emit(‘removeItem’, {{ json_encode($item->rowId) }})"
This way it does not matter what type you pass as argument: int, string, array - all will be perfectly passed to the php listener

1 Like