到目前为止,我已经设置了Laravel通知。我的设置是我要发送两个通知:“邮件”和“数据库”。我计划使用数据库通知,以便可以在某处显示该通知并允许用户清除它。
问题是,当我按预期将整个Noitification类排队时,所有内容都已排队...因此,这意味着甚至数据库通知也都排队了。我只希望将“邮件”部分排队,而数据库部分则立即存储到数据库中。这可能吗?
这是到目前为止的课程。
<?php
namespace App\Notifications;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use App\Document;
class ViewedDocument extends Notification implements ShouldQueue
{
use Queueable;
protected $document;
/**
* Create a new notification instance.
*
* @return void
*/
public function __construct(Document $document)
{
$this->document = $document;
}
/**
* Get the notification's delivery channels.
*
* @param mixed $notifiable
* @return array
*/
public function via($notifiable)
{
return ['mail','database'];
}
/**
* Get the mail representation of the notification.
*
* @param mixed $notifiable
* @return \Illuminate\Notifications\Messages\MailMessage
*/
public function toMail($notifiable)
{
return (new MailMessage)
->line('The introduction to the notification.')
->action('Notification Action', url('/'))
->line('Thank you for using our application!');
}
/**
* Get the array representation of the notification.
*
* @param mixed $notifiable
* @return array
*/
public function toArray($notifiable)
{
return [
'document_id' => $this->document->id,
'document_title' => $this->document->title
];
}
}
...然后我在某个地方的控制器中调用它...
// notification
Notification::send(User::find($document->created_by['user_id']), new ViewedDocument($document));
谢谢