blue-twilight/app/Notifications/DatabaseEmailNotification.php

53 lines
1.2 KiB
PHP

<?php
namespace App\Notifications;
use App\EmailLog;
use App\Facade\UserConfig;
use Illuminate\Mail\Mailable;
/**
* Enables a notification to use a Mailable to write to the database.
*/
trait DatabaseEmailNotification
{
/**
* Get the notification's delivery channels.
*
* @param mixed $notifiable
* @return array
*/
public function via($notifiable)
{
$drivers = [];
if (UserConfig::get('queue_emails'))
{
$drivers[] = QueueEmailDatabaseChannel::class;
}
else
{
$drivers[] = 'mail';
$drivers[] = SentEmailDatabaseChannel::class;
}
return $drivers;
}
/**
* Creates the EmailLog entry to write to the database.
* @param $notifiable
* @return EmailLog
*/
public function toEmailDatabase($notifiable)
{
return $this->toMail($notifiable)->buildEmailLog();
}
protected function setPropertiesOnMailable(Mailable $mailable, $notifiable)
{
// Set to and from properties accordingly
$mailable->from(UserConfig::get('sender_address'), UserConfig::get('sender_name'));
$mailable->to($notifiable->email, $notifiable->name);
}
}