尝试广播新事件时如何解决Laravel抛出FatalThrowableError问题

时间:2019-05-27 20:38:40

标签: php laravel pusher broadcasting

我正在跟踪一个教程,以使Laravel进行实时广播,但是经过仅仅几分钟的跟踪就陷入了困境。 Laravel向我抛出以下消息:“ 传递给Illuminate \ Database \ Grammar :: parameterize()的参数1必须为数组类型,给定整数,在/ home / vagrant / code / vendor / laravel / framework /中调用src / Illuminate / Database / Query / Grammars / Grammar.php行775

我已经尝试过多次重做教程,以确保我没有错过任何事情,但是经过几次尝试后问题仍然相同。 即使检查堆栈跟踪和文档也没有给我任何线索。

我在config/app.php中未注释以下行:

App\Providers\BroadcastServiceProvider::class,

我已将以下行添加到App\Providers\EventServiceProvider

use App\Events\RideCreated;
use App\Listeners\RideCreatedListener;

和同一文件中protected $listen = [之后的

    RideCreated::class => [
        RideCreatedListener::class,
    ],

这是用于测试(web.php)的路由的设置:

Route::get('/test', function(){
    event(new RideCreated());
    return "test";
});

这是RideCreated.php的样子:

<?php

namespace App\Events;

use Illuminate\Broadcasting\Channel;
use Illuminate\Queue\SerializesModels;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;

class RideCreated implements ShouldBroadcast
{
    use Dispatchable, InteractsWithSockets, SerializesModels;

    /**
     * Create a new event instance.
     *
     * @return void
     */
    public function __construct()
    {
        //
    }

    /**
     * Get the channels the event should broadcast on.
     *
     * @return \Illuminate\Broadcasting\Channel|array
     */
    public function broadcastOn()
    {
        return new Channel('RideCreated');
    }
}

侦听器(RideCreatedListener.php)如下:

<?php

namespace App\Listeners;

use App\Events\RideCreated;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;

class RideCreatedListener
{

    /**
     * Create the event listener.
     *
     * @return void
     */
    public function __construct()
    {
        //
    }

    /**
     * Handle the event.
     *
     * @param  RideCreated  $event
     * @return void
     */
    public function handle(RideCreated $event)
    {
        //
    }
}

我希望在访问/ test路由时看到屏幕上的测试,但实际上得到了显示的错误消息。

我的第一个想法是ShouldBroadcast中的RideCreated.php实现会导致问题,因为删除implement ShouldBroadcast会使错误消失。唯一的问题是删除它是没有选择的,因为它需要Pusher起作用。

1 个答案:

答案 0 :(得分:2)

这听起来可能很奇怪,但是我们一直在解决f2f问题。我的答案仅适用于可能会阅读此文章的其他人。

事实证明,未配置队列,因此Laravel可以解决默认队列。通过将{"level":30,"time":1559044530446,"pid":2462,"hostname":"PATRALTOP-46","prettyPrint":{"colorize":true},"req":{"id":10,"method":"GET","url":"/user/profile","headers":{"host":"localhost:3011","connection":"keep-alive","user-agent":"Mozilla36","accept":"*/*","accept-encoding":"gzip, deflate, br","accept-language":"en-US,en;q=0.9,ta;q=0.8","cookie":"menubShQ","if-none-match":"W2b7bpE08jO8lVNTEV/tg9OIRMd3fI"},"remoteAddress":"::1","remotePort":58260},"res":{"statusCode":304,"headers":{"x-powered-by":"Express","etag":"W2b7b-OpE08jO8lVNTEV/tg9OIRMd3fI"}},"responseTime":106,"msg":"something","v":1} 属性添加到$bradcastQueue类中,修复了该错误。参见Broadcast Queue