Larasocket: Laravel’s Newest Websocket Broadcasting Solution

Zach Vander Velden
1 min readJul 12, 2020

There is a new kid on the block in the Laravel broadcasting space. If you are looking for an affordable, pay as you go, no configuration, scalable solution then Larasocket is what you are looking for.

Setup

  1. Require the Larasocket PHP driver:
composer require larasocket/larasocket-driver

2. Add Larasocket as a broadcasting connection option in config/broadcasting.php:

'larasocket' => [
'driver' => 'larasocket',
'token' => env('LARASOCKET_TOKEN'),
],

3. Get a Larasocket token.

4. Update your .env to use Larasocket driver:

BROADCAST_DRIVER=larasocket
LARASOCKET_TOKEN=<token>
MIX_LARASOCKET_TOKEN="${LARASOCKET_TOKEN}"

Your Laravel application is now setup to dispatch events using Larasocket. Now let’s start listenting for these events:

  1. Include the Larasocket javascript driver:
npm i larasocket-js

2. Lastly, we need to update our Echo configuration in our bootstrap.js:

import Echo from 'laravel-echo';
import Larasocket from 'larasocket-js';
window.Echo = new Echo({
broadcaster: Larasocket,
token: process.env.MIX_LARASOCKET_TOKEN,
});

Your Laravel application is now setup to use Larasocket.

--

--