|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Backstage\Filament\Users\Notifications; |
| 4 | + |
| 5 | +use Illuminate\Support\Uri; |
| 6 | +use Illuminate\Bus\Queueable; |
| 7 | +use Filament\Facades\Filament; |
| 8 | +use Illuminate\Notifications\Notification; |
| 9 | +use Backstage\Laravel\Users\Eloquent\Models\User; |
| 10 | +use Illuminate\Notifications\Messages\MailMessage; |
| 11 | +use Backstage\Filament\Users\Pages\RegisterFromInvitationPage; |
| 12 | +use Backstage\Filament\Users\Actions\GenerateSignedRegistrationUri; |
| 13 | + |
| 14 | +class UserInvitationNotification extends Notification |
| 15 | +{ |
| 16 | + use Queueable; |
| 17 | + |
| 18 | + /** |
| 19 | + * Create a new notification instance. |
| 20 | + */ |
| 21 | + public function __construct() {} |
| 22 | + |
| 23 | + /** |
| 24 | + * Get the notification's delivery channels. |
| 25 | + * |
| 26 | + * @return array<int, string> |
| 27 | + */ |
| 28 | + public function via(User $notifiable): array |
| 29 | + { |
| 30 | + return config('users.events.auth.user_created.notification_delivery_channels', ['mail']); |
| 31 | + } |
| 32 | + |
| 33 | + /** |
| 34 | + * Get the mail representation of the notification. |
| 35 | + */ |
| 36 | + public function toMail(User $notifiable): MailMessage |
| 37 | + { |
| 38 | + /** |
| 39 | + * Mask the $dedicatedPanel variable as string to get the route name for the RegisterFromInvitationPage. |
| 40 | + * |
| 41 | + * @var string $dedicatedPanel |
| 42 | + */ |
| 43 | + $url = GenerateSignedRegistrationUri::run(user: $notifiable); |
| 44 | + |
| 45 | + return (new MailMessage) |
| 46 | + ->subject(__('Welcome to Our Platform')) |
| 47 | + ->greeting(__('Hello :name!', ['name' => $notifiable->getAttribute('name')])) |
| 48 | + ->line(__('We are excited to have you on board.')) |
| 49 | + ->action(__('Register'), $url) |
| 50 | + ->line(__('If you did not sign up, request this invitation, or expect to receive it, please ignore this email.')); |
| 51 | + } |
| 52 | + |
| 53 | + public function toArray(User $notifiable): array |
| 54 | + { |
| 55 | + return []; |
| 56 | + } |
| 57 | +} |
0 commit comments