Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pterodactyl
GitHub Repository: pterodactyl/panel
Path: blob/1.0-develop/app/Notifications/ServerInstalled.php
10266 views
1
<?php
2
3
namespace Pterodactyl\Notifications;
4
5
use Pterodactyl\Models\User;
6
use Illuminate\Bus\Queueable;
7
use Pterodactyl\Events\Event;
8
use Pterodactyl\Models\Server;
9
use Illuminate\Container\Container;
10
use Pterodactyl\Events\Server\Installed;
11
use Illuminate\Notifications\Notification;
12
use Illuminate\Contracts\Queue\ShouldQueue;
13
use Pterodactyl\Contracts\Core\ReceivesEvents;
14
use Illuminate\Contracts\Notifications\Dispatcher;
15
use Illuminate\Notifications\Messages\MailMessage;
16
17
class ServerInstalled extends Notification implements ShouldQueue, ReceivesEvents
18
{
19
use Queueable;
20
21
public Server $server;
22
23
public User $user;
24
25
/**
26
* Handle a direct call to this notification from the server installed event. This is configured
27
* in the event service provider.
28
*
29
* @phpstan-param Installed $event
30
*/
31
public function handle(Event|Installed $event): void
32
{
33
$event->server->loadMissing('user');
34
35
$this->server = $event->server;
36
$this->user = $event->server->user;
37
38
// Since we are calling this notification directly from an event listener we need to fire off the dispatcher
39
// to send the email now. Don't use send() or you'll end up firing off two different events.
40
Container::getInstance()->make(Dispatcher::class)->sendNow($this->user, $this);
41
}
42
43
/**
44
* Get the notification's delivery channels.
45
*/
46
public function via(): array
47
{
48
return ['mail'];
49
}
50
51
/**
52
* Get the mail representation of the notification.
53
*/
54
public function toMail(): MailMessage
55
{
56
return (new MailMessage())
57
->greeting('Hello ' . $this->user->username . '.')
58
->line('Your server has finished installing and is now ready for you to use.')
59
->line('Server Name: ' . $this->server->name)
60
->action('Login and Begin Using', route('index'));
61
}
62
}
63
64