https://www.youtube.com/watch?v=GGtCVVwDyWs
- Install laravel-websockets
composer require beyondcode/laravel-websockets
- Publish the migration file
php artisan vendor:publish --provider="BeyondCode\LaravelWebSockets\WebSocketsServiceProvider" --tag="migrations"
- Migrate
php artisan migrate
- publish the WebSocket configuration file:
php artisan vendor:publish --provider="BeyondCode\LaravelWebSockets\WebSocketsServiceProvider" --tag="config"
- change In .env file
BROADCAST_DRIVER=pusher
PUSHER_APP_ID=LaravelReal
PUSHER_APP_KEY=LaravelReal
PUSHER_APP_SECRET=LaravelRealSecret
PUSHER_APP_CLUSTER=mt1
- Uncomment Boardcast service provider in config/app.php
App\Providers\BroadcastServiceProvider::class,
- Add this line to boardcast message in routes/channel.php
Broadcast::channel('messages', function () {
return true;
});
- Define port and host in config/boardcasting.php
'pusher' => [
'driver' => 'pusher',
'key' => env('PUSHER_APP_KEY'),
'secret' => env('PUSHER_APP_SECRET'),
'app_id' => env('PUSHER_APP_ID'),
'options' => [
'cluster' => env('PUSHER_APP_CLUSTER'),
'encrypted' => true,
'host' => '127.0.0.1',
'port' => 6001,
'scheme' => 'http'
],
],
- Install Laravel echo
npm install --save laravel-echo pusher-js
- Define port and host in resources/js/bootstrap.js
window.Echo = new Echo({
broadcaster: 'pusher',
key: 'LaravelReal',
wsHost: window.location.hostname,
wsPort: 6001,
disableStats: true,
});
- Run
php artisan websocket:serve