Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/unity3d/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Laravel 5 发送通知时未使用自定义通知通道_Laravel 5_Notifications_Laravel 5.6 - Fatal编程技术网

Laravel 5 发送通知时未使用自定义通知通道

Laravel 5 发送通知时未使用自定义通知通道,laravel-5,notifications,laravel-5.6,Laravel 5,Notifications,Laravel 5.6,运行:PHP7.1.3/Laravel5.6.* 我已经成功地使用了Laravel自带的通知通道,但是由于某些原因,定制的通知通道没有被使用,更不用说构建了 预期: 调用$user->notify(new ContactResponse())应导致调用PushChannel的发送方法 实际: 当我调用$user->notify(new ContactResponse())时,ContactResponse的via方法(PushChannel)中指定的频道从不调用send,更不用说它的构造函数了

运行:
PHP7.1.3
/
Laravel5.6.*

我已经成功地使用了Laravel自带的通知通道,但是由于某些原因,定制的通知通道没有被使用,更不用说构建了

预期:

调用
$user->notify(new ContactResponse())
应导致调用PushChannel的发送方法

实际:

当我调用
$user->notify(new ContactResponse())
时,ContactResponse的
via
方法(PushChannel)中指定的频道从不调用
send
,更不用说它的构造函数了

我所做的:

我已将日志记录语句添加到所有相关方法机构,以验证问题,并了解:

  • ContactResponse的
    via
    方法被调用,但其
    toPush
    未被调用
  • 从不调用PushChannel的构造函数和
    send
    方法
  • 通过方法将“邮件”添加到ContactResponse的
    中的频道&a
    toMail
    方法添加到类中,确实会按预期在该频道上调用
我仔细检查了与此相关的Laravel 5.6文档,发现示例实现与我的实现之间没有差异

我审查了Laravel框架的问题/PRs,发现这表明这是Laravel当前实施的定制通知渠道中的一个问题:

问题:

我知道Laravel有推送通知通道的扩展,但我们希望使用我们的自定义实现。我们是否可以利用一种变通方法,以便在不修改Laravel源代码的情况下使用PushChannel


ContactResponse.php


肯定不是最漂亮的解决方案,但这在不修改Laravel源代码的情况下也能正常工作:

public function via(User $notifiable)
{
    // TODO: revert to proper implementation when fixed
    $channels = [PushChannel::class];
    if (in_array(PushChannel::class, $channels)) {
        $pushChannel = App::make(PushChannel::class);
        $pushChannel->send($notifiable, $this);
    }

    // return [PushChannel::class];
}
<?php

namespace App\Channels;

// ...imports

class PushChannel
{
    public function send(User $notifiable, Notification $notification)
    {
        $payload = $notification->toPush($notifiable)
        // business logic
    }
}
public function via(User $notifiable)
{
    // TODO: revert to proper implementation when fixed
    $channels = [PushChannel::class];
    if (in_array(PushChannel::class, $channels)) {
        $pushChannel = App::make(PushChannel::class);
        $pushChannel->send($notifiable, $this);
    }

    // return [PushChannel::class];
}