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

lvlNewbie's avatar

foreach varibale with alpine breaks livewire pagination

Hi, I have a model to edit post, where the post id is assigned to edit modal from a button like this

@click.prevent="$dispatch('edit-post-modal', { reply_id:'{{$comment->id}}' })"

The above works fine as for editing the post, but this breaks Livewire pagination, which complains as

Uncaught (in promise) DOMException: String contains an invalid character

when clicking on the Livewire next page button, that is this blade variable "{{$comment->id}}". I cannot use $wire.comment->id as this from a @foreach (comments as comment) .

How can I pass a loop variable to alpine js?

0 likes
2 replies
Snapey's avatar

view the browser source and check what the code has output to the browser

lvlNewbie's avatar

Problem is with the navigation to the second page. The first page is working fine and when clicking on the pagination links, no page changes and found this error on browser console. I couldn't find anything suspicious in the first page source, including the pagination links. And if I remove this blade variable, {{$comment->id}}, from the code, the pagination works fine.

Please or to participate in this conversation.