Sunny Kumar
Sunny Kumar

Reputation: 544

Laravel real time data update with mysql

How can I update a value to a view in laravel, whenever there is a change in mysql database. The update in the database can be from eloquent, external apps using api, or directly from phpmyadmin.

I don't want to use firebase.

Upvotes: 1

Views: 3793

Answers (1)

Hammerbot
Hammerbot

Reputation: 16364

You need to use websockets in order to do so.

Let's make a quick reminder of how a simple web app work:

  1. The user uses a browser to make a request to your server
  2. You server responds with a single response.
  3. If the user wants other information, he needs to make a new request to your server.

When you use websockets, here is what is happening:

  1. The user makes a request to your server
  2. Your server responds with a single response
  3. The response contains Javascript code that will connect your user browser to a websocket server (and this one can work in real time)
  4. The websocket server can trigger events and send them to your user browser. You can then use Javascript in order to make the updates in your views.

Laravel provides a wrapper to use websockets, Laravel Echo.

If you want to know more, I strongly encourage you to read the documentation about it: https://laravel.com/docs/5.4/broadcasting#installing-laravel-echo

Here is a video from Laracasts introducing Laravel Echo also, if you don't like to read documentation: https://laracasts.com/lessons/introducing-laravel-echo

Upvotes: 5

Related Questions