0
我已經創建了一個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 [
//
];
}
}
而且,在我的控制器調用該通知的方法:
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