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

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

在 Laravel 廣播中從多個私有頻道發送通知

在 Laravel 廣播中從多個私有頻道發送通知

PHP
溫溫醬 2023-03-04 17:11:05
我配置pusher, Laravel Broadcasting,Laravel Echo向我的用戶發送通知。它適用于單個私人頻道。我有兩個私人頻道。App.User{id}YouthAdd.YouthAdd{id}App.User{id}但是通知僅通過Channel傳遞我怎樣才能從其他渠道發送通知呢?我的用戶類namespace App;use Illuminate\Broadcasting\PrivateChannel;use Illuminate\Foundation\Auth\User as Authenticatable;use Illuminate\Notifications\Notifiable;class User extends Authenticatable{    use Notifiable;    /**     * The channels the user receives notification broadcasts on.     *     * @return string     */    public function receivesBroadcastNotificationsOn()    {        return 'App.User.'.$this->id;        return 'YouthAdd.YouthAdd.'.$this->id;    }}我的 Channels.php 路由文件Broadcast::channel('App.User.{id}', function ($user, $id) {    return (int) $user->id === (int) $id;});Broadcast::channel('YouthAdd.YouthAdd.{id}', function ($user, $id) {    return (int) $user->id === (int) $id;});我的前端<script>  var userId = $('meta[name="userId"]').attr('content');    Echo.private('App.User.' + userId)    .notification((notification) => {        toastr.warning(notification.title, notification.name, {closeButton: true, timeOut: 5000000});    });      Echo.private('YouthAdd.YouthAdd.' + userId)      .notification((notification) => {          console.log(notification.youth);          toastr.error(notification.youth.name, notification.youth.nic, {closeButton: true, timeOut: 5000000});      });    </script>任何人都可以回答這個問題嗎?
查看完整描述

3 回答

?
胡說叔叔

TA貢獻1804條經驗 獲得超8個贊

代替 :


public function receivesBroadcastNotificationsOn()

{

    return 'App.User.'.$this->id;

    return 'YouthAdd.YouthAdd.'.$this->id;

}

嘗試這個:


public function receivesBroadcastNotificationsOn()

{

     return [

        'App.User.'.$this->id,

        'YouthAdd.YouthAdd.'.$this->id

    ];

}


查看完整回答
反對 回復 2023-03-04
?
狐的傳說

TA貢獻1804條經驗 獲得超3個贊

這對我有用。


$channels = array();


        foreach ($this->athletes as $athlete) {

            array_push($channels, new PrivateChannel('athlete.' . $athlete->user->id));

        }


        array_push($channels, new PrivateChannel('user.' . $this->user->id));


return $channels;


查看完整回答
反對 回復 2023-03-04
?
冉冉說

TA貢獻1877條經驗 獲得超1個贊

嘗試這個:


        $channelNames = ['App.User.' . $this->id, 'YouthAdd.YouthAdd.'.$this->id];

        $channels = [];

        foreach ($channelNames as $channel) {

            $channels[] = new PrivateChannel($channel);

        }


        return $channels;


查看完整回答
反對 回復 2023-03-04
  • 3 回答
  • 0 關注
  • 148 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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