I have created a notification with laravel so that when the user submits the contact form he will receive a confirmation email.
I also set my queue driver as a database and performed all the migrations as the documentation says.
So I created my notification with php aritsan make: notification ContactConfirmation
implements 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 [
//
];
}
}
And the method that calls the notification in my 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));
}
When I submit the form a record is created in the jobs table with the notification information. But when I run the php artisan queue: work
command it only keeps processing until it reaches the limit of attempts.
[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
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire