rakeshthapac/laratime

Cool laravel package to broadcast database updates using websockets for realtime system

v1.0.0 2020-08-12 11:25 UTC

This package is auto-updated.

Last update: 2024-10-13 07:19:54 UTC


README

Provides a cool way to make your system realtime by sending real-time database updates using WebSockets

Installation

$ composer require rakeshthapac/laratime
$ npm install laratime-js

Usage

  • Just plug one trait into your model and you are ready to go
use \rakeshthapac\LaraTime\Traits\LaraTimeable;
// now all your database updates will be broadcasted through websockets

Usage (Frontend laratime-js)

  • import laratime from laratime-js and pass it the Echo instance
// in bootstrap.js
// first create a instance of a echo with correct credentials
import LaraTime from "laratime-js";
window.laratime = new LaraTime(window.Echo);
  • Now you are ready to listen for database changes
window.laratime
  .db("users")
  .on("added", (user) => addUser(user))
  .on("updated", (user) => updateUser(user))
  .on("deleted", (user) => deletesUser(user));
  • Using laratime-js you can listen to updates of a table using db(tableName) and by chaining on(eventName) you can listen to three different events:
    • added
    • updated
    • deleted
  • You can hook a callaback which accepts the added (or updated or deleted) model as the first argument as javascript object.