Search code examples
messaginglaravel-5.4

Laravel Live Messaging System


Heey everyone! I was doing a project using Laravel, and now I get to the point to make a private one-to-one chat. So far I made chat using Database, which requires reloadings and etc. But I want to enhance it, so that is was really good, with stuff like: writing, automatic receiving and sending (without reloading page).

What can you offer and why?


Solution

  • Use ajax or websocket.

    In ajax, you can simply fetch new messages and update the DOM by using setInterval.

    function start() {
        $start = setInterval(function() {
            fetch_chat_messages();    
        }, 3000);
    }
    start();
    

    The only disadvantage here is that the DOM keeps on refreshing.

    While in Websocket, realtime communication will be possible. I will recommend you to use http://socket.io/.

    Goodluck!