Skip to content

Commit 52f0196

Browse files
committed
Move broadcast channel registration to a routes file.
These are very similar to routes in that they are channel endpoints that your application supports and they also fully support route model binding in Laravel 5.4. Upgraded applications do not need to make this change if they do not want to.
1 parent b748931 commit 52f0196

File tree

3 files changed

+18
-6
lines changed

3 files changed

+18
-6
lines changed

app/Providers/BroadcastServiceProvider.php

+1-6
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,6 @@ public function boot()
1616
{
1717
Broadcast::routes();
1818

19-
/*
20-
* Authenticate the user's personal channel...
21-
*/
22-
Broadcast::channel('App.User.{userId}', function ($user, $userId) {
23-
return (int) $user->id === (int) $userId;
24-
});
19+
require base_path('routes/channels.php');
2520
}
2621
}

config/app.php

+1
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@
196196
'Artisan' => Illuminate\Support\Facades\Artisan::class,
197197
'Auth' => Illuminate\Support\Facades\Auth::class,
198198
'Blade' => Illuminate\Support\Facades\Blade::class,
199+
'Broadcast' => Illuminate\Support\Facades\Broadcast::class,
199200
'Bus' => Illuminate\Support\Facades\Bus::class,
200201
'Cache' => Illuminate\Support\Facades\Cache::class,
201202
'Config' => Illuminate\Support\Facades\Config::class,

routes/channels.php

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
/*
4+
|--------------------------------------------------------------------------
5+
| Broadcast Channels
6+
|--------------------------------------------------------------------------
7+
|
8+
| Here you may register all of the event broadcasting channels that your
9+
| application supports. The given channel authorization callbacks are
10+
| used to check if an authenticated user can listen to the channel.
11+
|
12+
*/
13+
14+
Broadcast::channel('App.User.{id}', function ($user, $id) {
15+
return (int) $user->id === (int) $id;
16+
});

0 commit comments

Comments
 (0)