I was following a tutorial to get Laravel to broadcast real-time but got stuck after just a few minutes of following along. Laravel throws the following message to me "Argument 1 passed to Illuminate\Database\Grammar::parameterize() must be of the type array, integer given, called in /home/vagrant/code/vendor/laravel/framework/src/Illuminate/Database/Query/Grammars/Grammar.php on line 775"
I've tried to redo the tutorial several times to make sure that I didn't miss a thing but the problem is still the same after several tries. Even checking the stack trace and documentation didn't give me any clue.
I've uncommented the following line in config/app.php
:
App\Providers\BroadcastServiceProvider::class,
I've added the following lines to App\Providers\EventServiceProvider
:
use App\Events\RideCreated;
use App\Listeners\RideCreatedListener;
and the following after protected $listen = [
in the same file
RideCreated::class => [
RideCreatedListener::class,
],
this is the setup of the route used for testing (web.php
):
Route::get('/test', function(){
event(new RideCreated());
return "test";
});
and this is how RideCreated.php
looks like:
<?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');
}
}
the listener (RideCreatedListener.php
) looks like this:
<?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)
{
//
}
}
I expected when visiting the /test rout to see test on screen but actually got the error message displayed.
my first thought was that the ShouldBroadcast
implementation in RideCreated.php
somehow causes the problem since removing implement ShouldBroadcast
makes the error disappear. the only problem is that removing it is no option since it's needed for Pusher to work.
This may sound strange, but we have been resolving this issue f2f. My answer is just for other people that might read this.
It turned out that the queue was not configured such that a default queue could be resolved by Laravel. The error was fixed by adding the $bradcastQueue
property to the RideCreated
class. See Broadcast Queue