亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Laravel5.8 推送器不工作。無法接收

Laravel5.8 推送器不工作。無法接收

PHP
慕斯709654 2021-10-15 10:12:55
我正在創建實時聊天應用程序。我已經在我的 laravel 和 vue.js 項目中設置了 pusher。但它不起作用。雖然我在控制臺中沒有任何錯誤。另外,我在網絡選項卡中沒有錯誤。我需要創建信使應用程序,所以我需要一個實時聊天功能。現在,我可以推送用戶的評論,但在其他用戶的窗口中,什么也沒有顯示。但它確實如此,一旦我刷新頁面。我認為我的推送器設置有問題,因為在推送器調試控制臺中,沒有執行任何會話。這是我的代碼。.envBROADCAST_DRIVER=pusherCACHE_DRIVER=fileQUEUE_CONNECTION=syncSESSION_DRIVER=fileSESSION_LIFETIME=120PUSHER_APP_ID=my idPUSHER_APP_KEY=my app keyPUSHER_APP_SECRET= my secret keyPUSHER_APP_CLUSTER=mt1廣播.php'pusher' => [            'driver' => 'pusher',            'key' => env('my key'),            'secret' => env('my secret key'),            'app_id' => env('my id'),            'options' => [                'cluster' => 'ap3',                'encrypted' => true,            ],廣播服務提供者.phpBroadcast::routes(['middleware' => ['auth:api']]);        require base_path('routes/channels.php');引導程序.jsimport Echo from 'laravel-echo'window.Pusher = require('pusher-js');window.Echo = new Echo({    broadcaster: 'pusher',    key: 'my key',    cluster: 'ap3',    encrypted: true});新消息.phpuse Illuminate\Contracts\Broadcasting\ShouldBroadcast;class NewMessage implements ShouldBroadcast{    use Dispatchable, InteractsWithSockets, SerializesModels;    public $message;    /**     * Create a new event instance.     *     * @return void     */    public function __construct(Message $message)    {        $this->message = $message;    }    /**     * Get the channels the event should broadcast on.     *     * @return \Illuminate\Broadcasting\Channel|array     */    public function broadcastOn()    {        return new PrivateChannel('messages.' . $this->message->to);    }    public function broadcastWith()    {        $this->message->load('fromContact');        return ["message" => $this->message];    }}路線/頻道.phpuse Illuminate\Support\Facades\Broadcast;
查看完整描述

2 回答

?
慕容森

TA貢獻1853條經驗 獲得超18個贊

在您的 send() 函數中,您應該編寫 broadcast(new NewMessage($message)); 廣播消息。


查看完整回答
反對 回復 2021-10-15
?
MMTTMM

TA貢獻1869條經驗 獲得超4個贊

你寫了嗎


window.Echo.private('channelName').listen('EventName',function(e){

})

在您的應用程序中收聽


查看完整回答
反對 回復 2021-10-15
  • 2 回答
  • 0 關注
  • 206 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號