Appearance
Live
Live updates on Laravel Reverb: new orders, the notification bell, who is editing a post, comments and a customer's orders appear without a reload.
kitloom/ · admins: kitloom/, kitloom/
Video lessons
Recorded in the Filament admin; the Nova admin works the same way.
Live updates on a kitloom site, through Laravel Reverb. While someone reads a page, what changes elsewhere shows on it without a reload:
- Comments. A comment approved in the admin, or posted by another visitor and approved at once, appears under the post on every open page.
- The account. A customer's order that moves on (paid, shipped, completed, refunded, a note for them) and a client's booking that is confirmed, moved or cancelled show in their account at once. The staff member's schedule follows their bookings too.
A visitor sees only what they would see after a reload. The page is told that something changed, never what: it asks the site again with its own visitor's eyes. Nobody's name, email or order is sent to anyone else's browser.
This works on Vue and React themes (Inertia). A Blade theme draws the same page as before and updates on a reload. In the admins: the bell of kitloom/notifications rings the moment a notice comes, the shop's order lists show a new order at once, a post open in two places says who is editing it, and the Assistant's answer can go on in the background. The admin section is kitloom/live-filament or kitloom/live-nova: it shows whether Reverb is running.
What the server needs
| What | Why |
|---|---|
A process manager that keeps php artisan reverb: running | Reverb is one long-lived process that holds the browsers' connections. While it is down, pages work as before and update only when reloaded |
The PHP extension pcntl | Reverb stops and restarts cleanly with it. Ubuntu's PHP has it; the official Docker images need docker- |
The web server passing / on to Reverb | Browsers connect to the site's own address, so nothing else has to be opened or certified |
Nothing goes into .. The keys the site and Reverb share are made from APP_; Reverb's own variables (REVERB_, REVERB_, REVERB_) win when you set them.
php artisan kitloom: writes all of this for your server, platform or Docker when the module is on.
Setting it up
- Switch the module on (Modules screen, or
composer require kitloom//live kitloom/ live- filament kitloom/).live- nova - Start Reverb:
php artisan reverb:. Locally, in a terminal next tostart php artisan serve. - Rebuild the theme once:
npm run build. The build adds the listening part (pusher-js loads only on sites with the module). - Open the admin: the "Live" section's badge says running.
php artisan live:says the same on the server and fails while Reverb does not answer.status
On your own machine
Reverb listens on port 8080. Without a web server passing / on, tell the browser where it is:
dotenv
VITE_REVERB_HOST=localhost
VITE_REVERB_PORT=8080
VITE_REVERB_SCHEME=httpnginx
Inside the site's server { … }. pusher-js connects to /; / itself may be a page of the site, and Reverb's HTTP API (/) stays on 127.0.0.1:
nginx
location ~ ^/app/[^/]+$ {
proxy_pass http://127.0.0.1:8080;
proxy_http_version 1.1;
proxy_set_header Host $http_host;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_read_timeout 1h;
}supervisor
/. Change the path, the user and the log file to match the server:
ini
[program:reverb]
process_name=%(program_name)s
command=php /var/www/site/artisan reverb:start --host=127.0.0.1 --port=8080
user=www-data
autostart=true
autorestart=true
redirect_stderr=true
stdout_logfile=/var/www/site/storage/logs/reverb.log
minfds=10000minfds raises the number of open files: each browser holds one connection. After a deploy, php artisan reverb: lets Reverb pick up the new code.
Settings
config/ (php artisan vendor:):
| Key | Default | What it does |
|---|---|---|
enabled | KITLOOM_, true | False keeps the module installed and sends nothing |
server., server., server. | REVERB_, REVERB_, REVERB_: 127., 8080, http | Where the site sends its broadcasts — Reverb on another host or container |
server. | 2 | Seconds a broadcast waits for Reverb before it is given up; the comment or the order is saved either way |
client., client., client. | VITE_, VITE_, VITE_: empty | Where browsers connect; empty — the site's own address |
filament., nova. | true | The "Live" section of each admin |
A site that broadcasts through Pusher or Ably keeps it: set BROADCAST_ and that service's keys as Laravel describes. The module then only adds the authorisation of private channels, and the theme needs that service's own client.
More than one Reverb server shares its connections through Redis: REVERB_.
For developers
A module makes one of its page parts live by implementing Kitloom\: live answers the event whose broadcast refreshes the part on that page, or null. The event is a Should on a channel from Kitloom\ (public('post', $id, 'comments'), private('user', $id, 'account')), with nothing in it but that something changed, sent through Kitloom\ — after the commit, and never at the cost of the write. A private channel is authorised with Live where the broadcaster is resolved. Something a person's account shows sends Kitloom\.
Without this module nothing is sent and every part is what it always was. Tests use Kitloom\.