mirror of
https://github.com/vitodeploy/vito.git
synced 2025-04-21 02:41:36 +00:00
* WIP notifications and other refactors - refactor notification channels - send notifications on events related to the servers and sites - delete server log files on server deletion - add telegram notification channel - add new icons - cache configs and icons on installation and updates - new navbar for dark mode and settings * discord channel * build assets * pint
58 lines
1.3 KiB
PHP
58 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\NotificationChannels;
|
|
|
|
use App\Contracts\Notification;
|
|
use App\Mail\NotificationMail;
|
|
use App\Models\NotificationChannel;
|
|
use Illuminate\Support\Facades\Mail;
|
|
use Throwable;
|
|
|
|
class Email extends AbstractNotificationChannel
|
|
{
|
|
public function createRules(array $input): array
|
|
{
|
|
return [
|
|
'email' => 'required|email',
|
|
];
|
|
}
|
|
|
|
public function createData(array $input): array
|
|
{
|
|
return [
|
|
'email' => $input['email'],
|
|
];
|
|
}
|
|
|
|
public function data(): array
|
|
{
|
|
return [
|
|
'email' => $this->notificationChannel->data['email'] ?? '',
|
|
];
|
|
}
|
|
|
|
public function connect(): bool
|
|
{
|
|
try {
|
|
Mail::to($this->data()['email'])->send(
|
|
new NotificationMail('Test VitoDeploy', 'This is a test email!')
|
|
);
|
|
} catch (Throwable) {
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
public function send(object $notifiable, Notification $notification): void
|
|
{
|
|
/** @var NotificationChannel $notifiable */
|
|
$this->notificationChannel = $notifiable;
|
|
$message = $notification->toMail($notifiable);
|
|
|
|
Mail::to($this->data()['email'])->send(
|
|
new NotificationMail($message->subject, $message->render())
|
|
);
|
|
}
|
|
}
|