错误:Laravel通知广播异常

时间:2017-07-08 11:35:51

标签: notifications laravel-5.4 pusher

我正在尝试在我正在处理的应用中构建实时通知系统。其中一个要求是,当ID过期时,应该向该特定用户发送通知。由于此任务需要每天最多运行,因此我开发了一个易于使用CRON作业(即Laravel Scheduler)运行的工匠命令。每件事都很好,即工匠命令运行并生成通知&存储在数据库中所有相关的东西。但每次生成通知时,页面都需要重新加载,这就是我被困住的地方。我试图让它实时发生但是一个非常奇怪的错误被抛出&我不知道这意味着什么。

以下是必要的代码:

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时,会生成通知&amp;在页面重新加载它更新通知的数量,但它没有实时发生。以下是控制台上显示的错误

[Illuminate\Broadcasting\BroadcastException]

注意:每当我重新加载页面时,Pusher Console都会显示相应的日志,例如已连接的私人频道和主持人&amp;所有那些意味着问题不在客户端的东西,(还)

1 个答案:

答案 0 :(得分:1)

刚刚找到了issue

的答案 由于我在本地开发,

必须加密false