У меня есть требование проекта, согласно которому мы хотим отправлять сообщения проверки электронной почты из SendGrid. Для этого я переопределил sendEmailVerificationNotification в App \ User
public function sendEmailVerificationNotification()
{
$this->notify(new \App\Notifications\SendGridEmailNotifications);
}
И сгенерировал класс уведомлений:
namespace App\Notifications;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\URL;
use Illuminate\Support\Facades\Lang;
use Illuminate\Support\Facades\Config;
use Log;
class SendGridEmailNotifications extends Notification
{
use Queueable;
public static $toMailCallback;
/**
* Create a new notification instance.
*
* @return void
*/
public function __construct()
{
//
}
/**
* Get the notification's delivery channels.
*
* @param mixed $notifiable
* @return array
*/
public function via($notifiable)
{
return ['mail'];
}
/**
* Get the mail representation of the notification.
*
* @param mixed $notifiable
* @return \Illuminate\Notifications\Messages\MailMessage
*/
public function toMail($notifiable)
{
/* Send via SendGrid. */
//Array of variables for SendGrid.
$payload = array();
$this->callSendGridAPI('mail/send', 'POST', $payload);
/*
return (new MailMessage)
->line('The introduction to the notification.')
->action('Notification Action', url('/'))
->line('Thank you for using our application!');
*/
return true;
}
/**
* Get the verification URL for the given notifiable.
*
* @param mixed $notifiable
* @return string
*/
protected function verificationUrl($notifiable)
{
return URL::temporarySignedRoute(
'verification.verify',
Carbon::now()->addMinutes(Config::get('auth.verification.expire', 60)),
['id' => $notifiable->getKey()]
);
}
/**
* Get the array representation of the notification.
*
* @param mixed $notifiable
* @return array
*/
public function toArray($notifiable)
{
return [
//
];
}
Моя проблема в том, что процесс предполагает возврат типа MailMessage для последующей отправки через MailChannel. Однако, если я удалю «через», например,
public function via($notifiable)
{
return;
}
Тогда класс вообще не запускается и ничего не происходит. Если я оставляю «почту» на месте, я сталкиваюсь с ошибкой в MailChannel, поскольку очевидно, что MailMessage не возвращается сюда.
Короче говоря, как я могу настроить это уведомление, чтобы просто нажать на API SendGrid и затем выйти? Могу ли я определить нулевой или тупиковый канал?
Спасибо!