|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace App\Notifications; |
| 4 | + |
| 5 | +use App\Models\Plugin; |
| 6 | +use Illuminate\Bus\Queueable; |
| 7 | +use Illuminate\Contracts\Queue\ShouldQueue; |
| 8 | +use Illuminate\Notifications\Messages\MailMessage; |
| 9 | +use Illuminate\Notifications\Notification; |
| 10 | + |
| 11 | +class NewPluginAvailable extends Notification implements ShouldQueue |
| 12 | +{ |
| 13 | + use Queueable; |
| 14 | + |
| 15 | + public function __construct( |
| 16 | + public Plugin $plugin |
| 17 | + ) {} |
| 18 | + |
| 19 | + /** |
| 20 | + * @return array<int, string> |
| 21 | + */ |
| 22 | + public function via(object $notifiable): array |
| 23 | + { |
| 24 | + if (! $notifiable->receives_new_plugin_notifications) { |
| 25 | + return []; |
| 26 | + } |
| 27 | + |
| 28 | + return ['mail', 'database']; |
| 29 | + } |
| 30 | + |
| 31 | + public function toMail(object $notifiable): MailMessage |
| 32 | + { |
| 33 | + return (new MailMessage) |
| 34 | + ->subject("New Plugin: {$this->plugin->name}") |
| 35 | + ->greeting('A new plugin is available!') |
| 36 | + ->line("**{$this->plugin->name}** has just been added to the NativePHP Plugin Marketplace.") |
| 37 | + ->action('View Plugin', url('/plugins')) |
| 38 | + ->line('You can manage your notification preferences in your account settings.'); |
| 39 | + } |
| 40 | + |
| 41 | + /** |
| 42 | + * @return array<string, mixed> |
| 43 | + */ |
| 44 | + public function toArray(object $notifiable): array |
| 45 | + { |
| 46 | + return [ |
| 47 | + 'title' => "New Plugin: {$this->plugin->name}", |
| 48 | + 'body' => "{$this->plugin->name} has just been added to the NativePHP Plugin Marketplace.", |
| 49 | + 'plugin_id' => $this->plugin->id, |
| 50 | + 'plugin_name' => $this->plugin->name, |
| 51 | + ]; |
| 52 | + } |
| 53 | +} |
0 commit comments