DEV Community

Sarfraz Ahmed
Sarfraz Ahmed

Posted on

2

Laravel SSE

Laravel package to provide Server Sent Events functionality for your app. You can use this package to show instant notifications to your users without them having to refresh their pages.


Checkout Laravel SSE

Top comments (4)

Collapse
 
kp profile image
KP

Will this work with a Nuxt.js Frontend talking to Laravel APIs?

Collapse
 
sarfraznawaz2005 profile image
Sarfraz Ahmed

Though I haven't worked with Nuxt.js but general idea is that package returns "message" event which you can hook into. For example, here is vanilla JS that can be used:

<script>
var es = new EventSource("{{route('__sse_stream__')}}");

es.addEventListener("message", function (e) {
    var data = JSON.parse(e.data);
    alert(data.message);
}, false);

</script>


`

I assume you can do something similar with Nuxt.JS too to capture "message" event and react to it.

Collapse
 
kp profile image
KP

Thank you! I'll give this a go when I find the time.

Collapse
 
gentlesammy profile image
Odunlade Samuel

Can i use this with react?

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay