我最近钻研了Laravel 5.3的Laravel-Echo和Pusher组合.我已经成功建立了公共频道,然后转向私人频道.我在Laravel从/ broadcast/auth路由返回403时遇到了麻烦,无论我做什么尝试授权操作(包括使用简单的返回true语句).谁能告诉我我做错了什么?
应用/供应商/ BroadcastServiceProvider.php:
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\Broadcast;
class BroadcastServiceProvider extends ServiceProvider
{
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
Broadcast::routes();
/*
* Authenticate the user's personal channel...
*/
Broadcast::channel('App.User.*', function ($user, $userId) {
return true;
});
}
}
resources/assets/js/booststrap.js:
import Echo from "laravel-echo"
window.Echo = new Echo({
broadcaster: 'pusher',
key: 'My-Key-Here'
});
window.Echo.private('App.User.1')
.notification((notification) => {
console.log(notification.type);
});
Run Code Online (Sandbox Code Playgroud)
我可以在我的Pusher调试控制台中看到事件和它的有效负载,一旦它到达auth路由就会失败.