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

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

Laravel Pusher 401 未經授權

Laravel Pusher 401 未經授權

PHP
jeck貓 2023-08-26 09:57:12
我無法讓我的事件在 laravel 7.x、pusher、laravel-echo 上運行。我已經正確設置了所有內容,但仍然收到 401 錯誤。我還在 .env 文件中將broadcast_driver 設置為推送器。如果有人可以提供幫助,我將不勝感激。評論事件.php<?phpnamespace App\Events;use Illuminate\Broadcasting\Channel;use Illuminate\Broadcasting\InteractsWithSockets;use Illuminate\Broadcasting\PresenceChannel;use Illuminate\Broadcasting\PrivateChannel;use Illuminate\Contracts\Broadcasting\ShouldBroadcast;use Illuminate\Foundation\Events\Dispatchable;use Illuminate\Queue\SerializesModels;class CommentEvent implements ShouldBroadcast{    use Dispatchable, InteractsWithSockets, SerializesModels;    public $comment;    /**     * Create a new event instance.     *     * @return void     */    public function __construct($comment)    {        $this->comment =$comment;    }    /**     * Get the channels the event should broadcast on.     *     * @return \Illuminate\Broadcasting\Channel|array     */    public function broadcastOn()    {        return new Channel('comment-channel');    }    public function broadcastAs()        {            return 'newComment';        }}CommentController.php<?phpnamespace App\Http\Controllers;use Illuminate\Http\Request;use App\Events\CommentEvent;use App\Comment;class CommentController extends Controller{   public function index(){      return view('comments');   }   public function fetchComments(){      $comments =Comment::all();      return response()->json($comments);   }   public function store(Request $request){      $comment =Comment::create($request->all());      event(new CommentEvent($comment));      return response()->json('ok');   }}
查看完整描述

1 回答

?
慕姐4208626

TA貢獻1852條經驗 獲得超7個贊

確保將$user傳遞到通道路由回調中。將此代碼替換為您的頻道路由。那么你就可以走了:)

Broadcast::channel('comment-channel', function ($user) {
    return true;
});



查看完整回答
反對 回復 2023-08-26
  • 1 回答
  • 0 關注
  • 156 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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