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

meez's avatar
Level 1

livewire events with alpine js

i am trying to make reusable alert component .. using livewire events and listening with alpine

the problem is that i need to make redirect in some components after dispatching the event, that cause the alert disapper .. how to handle that?

0 likes
8 replies
meez's avatar
Level 1

@vincent15000 as i understand, teleport is to solve z-index peoblem within the nested components .. my case is that i make $this->dispatch inside method and the alert component listen to the event through alpine .. this works well .. but after i dsipatch the event i make redirect .. so the alert disappear .

1 like
vincent15000's avatar

@meez The teleportation is not only to solve z-index problem, it's only an example.

With the teleportation, you have teleport a piece of code necessarily outside the Livewire component, for example you can teleport at the root of the body tag.

So I think that the teleported code will remain while loading another component.

I don't have tested it, but it's worth trying it ;).

meez's avatar
Level 1

@vincent15000 actually my alert component rendered in the layout .. not inside the livewire component

1 like
vincent15000's avatar

@meez You should try the teleportation.

You can also choose to save the message in the session and retrieve this message from the session in the new page after redirection. This will avoid the alert message to disappear.

1 like
meez's avatar
Level 1

@vincent15000 yes .. @persist did the job with redirect navidate = true .. although it need the component present within all the livewire components .. but great .. thank you for help

1 like

Please or to participate in this conversation.