阅读(3017) (10)

Laravel 8 自定义通知频道

2021-07-06 09:24:46 更新

如果您想要自定义被通知实体在某个通道上接收广播通知,可以在被通知实体上定义一个 receivesBroadcastNotificationsOn 方法:

<?php

namespace AppModels;

use IlluminateBroadcastingPrivateChannel;
use IlluminateFoundationAuthUser as Authenticatable;
use IlluminateNotificationsNotifiable;

class User extends Authenticatable
{
    use Notifiable;

    /**
     * 用户接收广播通知的通道。
     *
     * @return string
     */
    public function receivesBroadcastNotificationsOn()
    {
        return 'users.'.$this->id;
    }
}