我已经使用laravel创建了一个通知,以便当用户提交联系表单时,他会收到一封确认电子邮件。
我还将队列驱动程序设置为数据库,并按文档说明执行所有迁移。
所以我用php aritsan make: notification ContactConfirmation
实现了ShouldQueue:
<?php
namespace App\Notifications;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
class ContactConfirmation extends Notification implements ShouldQueue
{
use Queueable;
public $data;
public function __construct($data)
{
$this->data = $data;
}
public function via($notifiable)
{
return ['mail'];
}
public function toMail($notifiable)
{
return (new MailMessage)
->subject('Dúvida: '.ucfirst($this->data->subject))
->greeting('Olá '.$this->data->name.'!')
->line('Recebemos a sua mensagem e entraremos em contato assim que possível.')
->line('Obrigado por usar a Mapa do Carro!');
}
public function toArray($notifiable)
{
return [
//
];
}
}
在我的Controller中调用通知的方法:
public function sendEmail($data)
{
$user = \App\User::find(1);
$data['name'] = $user->name;
// Mail::to($guest->email)
// ->queue(new ContactConfirmation($guest));
$user->notify(new ContactConfirmation($data));
}
当我提交表单时,会在作业表中创建包含通知信息的记录。但是当我运行php artisan queue: work
命令时,它只会继续处理,直到达到尝试的极限。
[2017-04-27 01:05:06] Processing: App\Notifications\ContactConfirmation
[2017-04-27 01:05:06] Processing: App\Notifications\ContactConfirmation
[2017-04-27 01:05:06] Processing: App\Notifications\ContactConfirmation
[2017-04-27 01:05:07] Processing: App\Notifications\ContactConfirmation
[2017-04-27 01:05:07] Processing: App\Notifications\ContactConfirmation
[2017-04-27 01:05:07] Processing: App\Notifications\ContactConfirmation
[2017-04-27 01:05:07] Processing: App\Notifications\ContactConfirmation
[2017-04-27 01:05:08] Processing: App\Notifications\ContactConfirmation
[2017-04-27 01:05:08] Processing: App\Notifications\ContactConfirmation
[2017-04-27 01:05:08] Processing: App\Notifications\ContactConfirmation
[2017-04-27 01:05:08] Processing: App\Notifications\ContactConfirmation
[2017-04-27 01:05:08] Processing: App\Notifications\ContactConfirmation
[2017-04-27 01:05:09] Processing: App\Notifications\ContactConfirmation
[2017-04-27 01:05:09] Processing: App\Notifications\ContactConfirmation
[2017-04-27 01:05:09] Processing: App\Notifications\ContactConfirmation
[2017-04-27 01:05:09] Processing: App\Notifications\ContactConfirmation
答案 0 :(得分:0)
您正在将数组传递给if-elif-else
类,而ContactConfirmation
是一个对象