page = $page; $this->user = $user; $this->action = $action; } /** * Get the notification's delivery channels. * * @return array */ public function via(object $notifiable): array { $channels = []; $prefs = $notifiable->preferences ?? []; // Se o admin quiser receber notificações de alterações em páginas if ($prefs['notifications_page_actions'] ?? true) { if ($prefs['notifications_email'] ?? true) { $channels[] = 'mail'; } if ($prefs['notifications_system'] ?? true) { $channels[] = 'database'; } } return $channels; } /** * Get the mail representation of the notification. */ public function toMail(object $notifiable): MailMessage { $actionText = $this->action === 'created' ? 'criada' : 'atualizada'; return (new MailMessage) ->subject('Página ' . ucfirst($actionText) . ' - ' . config('app.name')) ->greeting('Olá, ' . $notifiable->name) ->line('Uma página do site foi ' . $actionText . ' por ' . $this->user->name . '.') ->line('**Título da Página:** ' . $this->page->title) ->line('**Slug:** ' . $this->page->slug) ->action('Gerenciar Páginas', route('admin.pages.index')) ->line('Obrigado por usar nosso sistema!'); } /** * Get the array representation of the notification. * * @return array */ public function toArray(object $notifiable): array { $actionText = $this->action === 'created' ? 'criada' : 'atualizada'; return [ 'page_id' => $this->page->id, 'name' => $this->user->name, 'email' => $this->user->email, 'action' => $this->action, 'message' => "Página '{$this->page->title}' foi {$actionText}.", 'link' => route('admin.pages.edit', $this->page->id) ]; } }