laravel throws exception when I want to broadcast on a channel
Message posted events
<?php
namespace App\Events;
use App\Message;
use App\User;
use Illuminate\Broadcasting\Channel;
use Illuminate\Queue\SerializesModels;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Broadcasting\PresenceChannel;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
class MessagePosted implements ShouldBroadcast
{
use Dispatchable, InteractsWithSockets, SerializesModels;
/**
* Message
* @var Message
*/
public $message;
/**
* User
* @var User
*/
public $user;
/**
* Create a new event instance.
*
* @return void
*/
public function __construct(Message $message,User $user)
{
//
$this->$message= $message;
$this->$user=$user;
}
/**
* Get the channels the event should broadcast on.
*
* @return \Illuminate\Broadcasting\Channel|array
*/
public function broadcastOn()
{
return new PrsenceChannel('chatroom');
}
}
web.php
Route::post("/new-message",function(){
$message = request()->get('message');
\Log::error("hi masoud ".$message);
$user = Auth::user();
//CREATE ACTS AS INSERTING
error_log("message");
$the_message = $user->messages()->create([
'message'=>$message,
]);
event(new MessagePosted($the_message,$user));
});
Channels
Broadcast::channel('chatroom', function ($user) {
return $user;
});
typo?
return new PrsenceChannel('chatroom');
should be:
return new PresenceChannel('chatroom');
no I fixed that but the problem keeps on .
I would try to find answers here, it seems _not_ to be a bug with Laravel, but a bug within your app...
thanks my efforts is ongoing to find the app ,_possible_ bug.
the problem seems to be from pusher .since it is responding me with status 0 .
Had the same problem and solved it by setting PUSHER_APP_CLUSTER=eu in the .env.