Guide to using sockets in your Laravel application

Daan
Daan
May 22 · 5 min read

Part 1: Backend

Pusher

composer require pusher/pusher-php-server "~3.0"
The credentials will be displayed in the Pusher dashboard, once you have selected your app

Time to start making the chatbox

Creating the controller

php artisan make:controller ChatController

Event

php artisan make:event MessageSend

BroadcastServiceProvider

Uncomment the BroadcastServiceProvider
php artisan config:cache

Part 2: Frontend

Receiving broadcasts

npm install --save laravel-echo pusher-js
Uncomment the Laravel Echo code

Chatbox

Chitty chat

The chatbox in action in two tabs!

Debugging

BroadcastException

'curl_options' => [
CURLOPT_SSL_VERIFYHOST => 0,
CURLOPT_SSL_VERIFYPEER => 0,
],

The Startup

Medium's largest active publication, followed by +479K people. Follow to join our community.

Daan

Written by

Daan

Backend developer from The Netherlands. Crypto enthusiast.

The Startup

Medium's largest active publication, followed by +479K people. Follow to join our community.