【发布时间】:2018-08-14 15:50:51
【问题描述】:
我设置了以下通知
BillProcessed.php
<?php
namespace App\Notifications;
use App\Bill;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;
use Illuminate\Notifications\Messages\BroadcastMessage;
class BillProcessed extends Notification
{
use Queueable;
protected $bill;
/**
* Create a new notification instance.
*
* @return void
*/
public function __construct(Bill $bill)
{
$this->bill = $bill;
}
/**
* Get the notification's delivery channels.
*
* @param mixed $notifiable
* @return array
*/
public function via($notifiable)
{
// Only send mail if this feature is turned on
return config('features.bill_processed_mail', false) ? ['mail', 'broadcast', 'database'] : ['broadcast', 'database'];
}
/**
* Get the mail representation of the notification.
*
* @param mixed $notifiable
* @return \Illuminate\Notifications\Messages\MailMessage
*/
public function toMail($notifiable)
{
return (new MailMessage)
->greeting("Hello {$notifiable->name},")
->line('A new Bill has been processed!')
->action('View Bill', url('/bills/' . $this->bill->id))
->line('Thank you for using our application!');
}
/**
* Get the database representation of the notification.
*
* @param mixed $notifiable
* @return array
*/
public function toDatabase($notifiable)
{
return [
'message' => 'New Bill Processed',
'bill' => $this->getBillStub(),
];
}
/**
* Get the database representation of the notification.
*
* @param mixed $notifiable
* @return array
*/
public function toBroadcast($notifiable)
{
return new BroadcastMessage([
'data' => [
'message' => 'New Bill Processed',
'bill' => $this->getBillStub(),
],
]);
}
protected function getBillStub()
{
return [
'id' => $this->bill->id,
'due_date' => $this->bill->due_date->format('m-d-Y'),
'site_code' => $this->bill->account->site->code,
'site_name' => $this->bill->account->site->name,
'type' => $this->bill->account->types->first()->name,
'created' => $this->bill->created_at->format('m-d-y H:i:s'),
];
}
}
这在我的本地机器上运行良好,但是当我将它放到我们的暂存环境中时,它出现了问题。
首先,邮件可以正常发送到日志。数据库也充满了通知。广播正在被队列接收,但它只是像这样坐在那里:
它没有失败或超时,它只是处于这种状态。我已经尝试重新启动主管,但仍然没有。
我还四重检查了我的 env 文件中是否有正确的 PUSHER 信息。
【问题讨论】:
-
看起来它处于暂停状态 - 你可以尝试 php artisan horizon:continue
-
我做了所有适用的地平线命令。请参阅下面的答案:)