阅读(2992) (0)

Laravel 8 自定义通知频道

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

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

<?php

namespace App\Models;

use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;

class User extends Authenticatable
{
    use Notifiable;

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