46 lines
1.5 KiB
PHP
Raw Normal View History

<?php
2023-06-14 11:54:00 +02:00
namespace App\Notifications\Notifications;
2023-06-01 12:15:33 +02:00
use App\Notifications\Channels\EmailChannel;
use App\Notifications\Channels\DiscordChannel;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;
2023-06-01 12:15:33 +02:00
class TestNotification extends Notification implements ShouldQueue
{
use Queueable;
2023-06-20 15:04:46 +02:00
public string|null $type = null;
public function __construct(string|null $type = null)
{
$this->type = $type;
}
public function via(object $notifiable): array
{
2023-05-25 17:27:52 +01:00
$channels = [];
2023-06-20 15:04:46 +02:00
if (($this->type === 'smtp' || is_null($this->type)) && $notifiable->extra_attributes?->get('smtp_enabled') && $notifiable->extra_attributes?->get('notifications_smtp_test')) {
2023-06-19 14:31:42 +02:00
$channels[] = EmailChannel::class;
}
2023-06-20 15:04:46 +02:00
if (($this->type === 'discord' || is_null($this->type)) && $notifiable->extra_attributes?->get('discord_enabled') && $notifiable->extra_attributes?->get('notifications_discord_test')) {
2023-06-19 14:31:42 +02:00
$channels[] = DiscordChannel::class;
}
2023-05-25 17:27:52 +01:00
return $channels;
}
2023-06-12 12:00:01 +02:00
public function toMail(): MailMessage
{
2023-06-19 14:31:42 +02:00
$mail = new MailMessage();
$mail->subject("Coolify Test Notification");
$mail->view('emails.test');
return $mail;
}
2023-06-12 12:00:01 +02:00
public function toDiscord(): string
{
2023-06-19 14:31:42 +02:00
return 'This is a test Discord notification from Coolify.
[Go to your dashboard](' . base_url() . ')';
}
}