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

AlexDFCH's avatar

Just a guide aboute Inertia.

Hi, I'm new at front-end. lately I start learning Vue and Inertia for build my front-end. I started by a simple blog.

What I want is: When a new comment added by users then a Number shows off the front of comments section in admin panel. without I reload the admin panel.

First I think one solution is use Inertia.reload({ only: ['countOfNewComments'] }) every 5 seconds but now I think it's kinda stupid.

I read all Inertia docs and seen some tutorial in Youtube and now I can build a CRUD with table filtering and all these regular stuff but nowhere I found this simple notif thing in the examples.

No! I don't want you to write code for me :) I just need a clue. I really would be thankful if you guide me and tell me what should I do in general or even if you know an example, give me the link of it please.

Thank you my friends.

0 likes
11 replies
vincent15000's avatar

Reloading every 5 second is probably a good idea if you need to display the number of comments written by any user.

You can also work with channels and then you can listen to an event every time a new comment is added.

AlexDFCH's avatar

Thank you. Would you explain more your second idea please? What you mean about "channels"? which channels exactly? And when I listen something at the back-end, how I tell the the Inertia at front-end to apply it?

Sorry for a lot of noob questions.

1 like
Sinnbeck's avatar
Sinnbeck
Best Answer
Level 102

What you are describing is called polling. That is indeed one solution. I would do it with plain javascript (Fetch or axios) instead of involving Inertia.

Another solution is to use websockets. This allows the server to "push" the message to the browser. Laravel has a built in implementation for this using Pusher (if you want it to be free, you can self-host Soketi) https://laravel.com/docs/9.x/broadcasting#main-content

2 likes
AlexDFCH's avatar

Thank you.

It's much more complicated than expect :) but at least I have some clues to search about it now.

And more important, I find out it's not about Inertia!

So now I should search about "polling", "broadcasting", "Pusher" and "Soketi".

Thank you again.

1 like
Sinnbeck's avatar

@AlexDFCH Personally I use broadcasting for a chat system and I self host soketi. But you can start with pusher.com (I think they have a free tier). They are compatible so you can switch later if you want :)

2 likes
AlexDFCH's avatar

@Sinnbeck Maby this question is funny, but I'm wondering why we need another thing (Pusher or Soketi) for doing something simple like sending just some data between back-end and front-end?

What is here that I don't understand? How I should have a better view about this?

(Honestly, sometimes I think I'm too old for this job. you open a door and you see a room with 5 other closed doors and you feel confused)

Sinnbeck's avatar

@AlexDFCH Yeah it can indeed be overkill with websockets :)

You can easily just do the polling version. Have a setInterval() function that calls axios (It ships with inertia), that calls that backend

setInterval(function() {
    window.axios
            .get('/some/backend/url')
            .then(({data}) => {
                //some logic
            })
}, 5000);

Or inertia if you still prefer that :)

setInterval(function() {
    Inertia.reload({ only: ['countOfNewComments'] })
}, 5000);

41 myself, and it is never to late to learn :)

1 like
Sinnbeck's avatar

@AlexDFCH Happy to help. You can test out both version and see what you like. Maybe the inertia version works perfectly for you and then just go with that :)

1 like

Please or to participate in this conversation.