【发布时间】:2017-05-22 22:21:48
【问题描述】:
我正在使用 L5.3。
我有很多可排队的 Laravel 通知,它们在 Redis 上运行良好。删除某些 Eloquent 模型的通知除外。
这里是通知源示例:
<?php
namespace App\Notifications\Games;
use App\Helpers\NotificationHelper;
use App\Game;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Support\Facades\Log;
class Deleted extends Notification implements ShouldQueue
{
use Queueable;
public $game;
private $game_id;
public function __construct($game_id)
{
$this->game_id = $game_id;
$this->game = Game::withTrashed()->with('situation')->find($game_id);
// Log::info($this->game) here shows everything is ok
}
/**
* Get the notification's delivery channels.
*
* @param mixed $notifiable
* @return array
*/
public function via($notifiable)
{
return ['database'];
}
/**
* Get the array representation of the notification.
*
* @param mixed $notifiable
* @return array
*/
public function toDatabase($notifiable)
{
return [
'game_id' => $this->game->id,
'html' => '' . view('notifications.games.deleted', ['id' => $this->id, 'game' => $this->game, 'notifiable' => $notifiable])
];
}
}
还有我如何发送它:
$user->notify(new Deleted($id));
如果我删除 implements ShouldQueue,通知会起作用。但由于使用了多种外部服务(例如 Telegram、Facebook、One signal 等),我需要排队,并且可以将一些通知发送给很多用户。
storage\logs\laravel.log 和 storage\logs\worker.log 文件中也没有错误。 failed_jobs 表中没有项目。
是的,我正在使用 soft deleting 的模型。
【问题讨论】:
标签: php laravel laravel-5 notifications laravel-5.3