*/ public function via(object $notifiable): array { return config('site.submissions.notify_by_mail', false) ? ['database', 'mail'] : ['database']; } /** * @return array */ public function toDatabase(object $notifiable): array { return FilamentNotification::make() ->title($this->title()) ->body($this->application->subject()) ->icon('heroicon-o-inbox-arrow-down') ->iconColor('success') ->actions([ Action::make('view') ->label(__('panel.applications.actions.open')) ->url(ApplicationResource::getUrl('view', ['record' => $this->application])) ->markAsRead(), ]) ->getDatabaseMessage(); } public function toMail(object $notifiable): MailMessage { return (new MailMessage) ->subject($this->title()) ->greeting(__('panel.applications.mail.greeting')) ->line($this->application->subject()) ->line(__('panel.applications.mail.from', [ 'name' => $this->application->name, 'email' => $this->application->email, ])) ->action( __('panel.applications.actions.open'), ApplicationResource::getUrl('view', ['record' => $this->application]), ); } protected function title(): string { return __("panel.applications.notification.{$this->application->kind->value}", [ 'name' => $this->application->name, ]); } /** * Everyone allowed to read the inbox. * * Resolved through `can()` rather than a permission scope so super admins * are included: they hold no explicit permissions at all, only the * Gate::before hook that grants them everything. * * @return Collection */ public static function recipients(): Collection { // Recomputed rarely: a submission arriving in a burst should not cost // one query per message to answer a question whose answer only changes // when somebody edits a role. $ids = Cache::remember('applications:recipients', now()->addMinutes(5), fn () => User::query() ->where('is_active', true) ->get() ->filter(fn (User $user) => $user->can('applications.view_any')) ->pluck('id') ->all()); return User::query()->whereKey($ids)->get(); } }