我有点像菜鸟;如果我遗漏了一些明显的东西,请原谅我。
我的应用程序中有这个类来设置广播频道(对于Pusher):
<?php
namespace App\Providers;
use App\Models\Thread;
use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\Broadcast;
class BroadcastServiceProvider extends ServiceProvider
{
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
Broadcast::routes(['middleware' => ['api', 'jwt.auth']]);
/*
* Authenticate the user's personal channel...
*/
Broadcast::channel('users.*.threads', function ($user, $userId) {
return $user->obfuscated_id == $userId;
});
Broadcast::channel('threads.*', function ($user, $threadId) {
return $user->can('participate', Thread::findByObfuscation($threadId));
});
Broadcast::channel('notifications.*', function ($user, $notifiableId) {
return $user->obfuscated_id == $notifiableId;
});
Broadcast::channel('messages.*', function ($user, $userId) {
return $user->obfuscated_id == $userId;
});
}
}
这在Laravel 5.3上工作正常,但在升级(使用Laravel Shift)到5.4后,我开始收到错误:
<!-- language: lang-none -->
Symfony\Component\Debug\Exception\FatalThrowableError: Type error: Too few arguments to function App\Providers\BroadcastServiceProvider::App\Providers\{closure}(), 1 passed in /home/vagrant/Development/Peeps/api/vendor/laravel/framework/src/Illuminate/Broadcasting/Broadcasters/Broadcaster.php on line 68 and exactly 2 expected in /home/vagrant/Development/Peeps/api/app/Providers/BroadcastServiceProvider.php:35
比较Broadcaster.php文件的上一版本和新版本,有一些变化,最可疑的是,这一行:
$parameters = $this->extractAuthParameters($pattern, $channel, $callback);
现在传递一个额外的参数$ callback。
我认为这与回调函数在堆栈中传递的方式有关,我想知道是否有更好的方法来编写对更新的Illuminate类更友好的BroadcastServiceProvider.php。
任何帮助都非常感谢!
答案 0 :(得分:0)
I think shift missed a step. Plz follow this to get this solved.
https://laravel.com/docs/5.4/upgrade
在Laravel 5.3中定义通道名称占位符时,使用*字符。在Laravel 5.4中,您应该使用{foo}样式占位符来定义这些占位符,例如路径:
Broadcast :: channel('App.User。{userId}',function($ user,$ userId){ return(int)$ user-&gt; id ===(int)$ userId; });