2

我已经在我的项目中安装了https://github.com/laravel-notification-channels/webpush 但是发送通知时什么都没有。它不起作用这是 laravel 通知文档:https ://laravel.com/docs/5.5/notifications

这是我的代码 - 我创建了一个通知:

class AccountApproved extends Notification {
use Queueable;

public function __construct()
{
    //
}

public function via($notifiable)
{
    return [WebPushChannel::class];
}

public function toArray($notifiable)
{
    return [
        'title' => 'Hello from Laravel!',
        'body' => 'Thank you for using our application.',
        'action_url' => 'https://laravel.com',
        'created' => Carbon::now()->toIso8601String()
    ];
}

public function toWebPush($notifiable, $notification)
{
    return WebPushMessage::create()
        ->title('Hello from Laravel!')
        ->icon('/notification-icon.png')
        ->body('Thank you for using our application.')
        ->action('View app', 'view_app');
}}

我在我的控制器中调用通知:

     $when = Carbon::now();

    $request->user()->notify((new AccountApproved)->delay($when));

但我 Webpush 不起作用。怎么了?

4

2 回答 2

1

确保您正在运行这样的队列工作者:

php artisan queue:work

在命令行中。否则将不会发送排队的通知。

如果它无助于查看您的错误日志并验证其中是否有任何错误

于 2017-10-11T19:16:07.393 回答
0

要使该方法delay()起作用,您必须添加到您的通知中implements ShouldQueue

class AccountApproved extends Notification implements ShouldQueue { ... }

和 ofcuse Illuminate\Contracts\Queue\ShouldQueue;在你上课之前

于 2020-01-24T10:40:25.817 回答