Error: Laravel Notifications Broadcast Exception

Error: Laravel Notifications Broadcast Exception

我正在尝试在我正在开发的应用程序中构建一个实时通知系统。其中一项要求是,当 ID 过期时,应向该特定用户发送通知。由于此任务每天最多需要 运行,因此我开发了一个 artisan 命令,可以很容易地 运行 使用 CRON 作业,即 Laravel 调度程序。一切正常,即 artisan 命令是 运行 并且通知已生成并存储在数据库和所有相关内容中。但是每次生成通知时,都需要重新加载页面,这就是我卡住的地方。我试图让它实时发生,但抛出了一个非常奇怪的错误,我不知道它是什么意思。

这是必要的代码:

Artisan.file

<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;

use App\User;
use Carbon\Carbon;
use App\Notifications\UserIdExpired;

class UpdateCatalog extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'check:expiry';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'dummy command to check its purpose';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        $ZERO = 0;
        $MONTH = 30;
        $today = Carbon::today();
        $users = User::all();
        foreach($users as $user){
            $today = Carbon::today();
            $expiryDate = $user->qidexpire_on;

            if($today->diffInDays($expiryDate, false) <= $MONTH && $today->diffInDays($expiryDate, false) >= $ZERO){
               $this->info($user);
                $this->info($expiryDate->diffInDays($today));
                $user->notify(new UserIdExpired);

            } else {


            } 
            }

        }
    }
}

Notification.file

<?php

namespace App\Notifications;

use Carbon\Carbon;

use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Messages\BroadcastMessage;


class UserIdExpired extends Notification
{
    use Queueable;


    public function via($notifiable)
    {
        return ['database', 'broadcast'];
    }

    public function toDatabase($notifiable)
    {
        return [
            'user' => $notifiable,
            'id_expired' => Carbon::now()
        ];
    }

    public function toBroadcast($notifiable)
    {
        return new BroadcastMessage([
            'user' => $notifiable,
            'id_expired' => Carbon::now()
        ]);
    }


}

当我从控制台 运行 php artisan check:expiry 时,会生成通知并在页面重新加载时更新通知数量,但它不是实时发生的。以下是控制台上显示的错误

[Illuminate\Broadcasting\BroadcastException]

注意:每当我重新加载页面时,Pusher 控制台都会显示相应的日志,例如已连接的私人频道和主机以及所有这些,这意味着问题不在客户端,(还)

刚刚在这个 issue

上找到了答案

必须加密 false 因为我在本地开发