team; if ($team === null || ! $team->notify_on_api_lead) { return; } $recipients = $team->allUsers(); if ($recipients->isEmpty()) { return; } [$label, $url] = $this->resolveLabelAndUrl($record); defer(function () use ($recipients, $label, $record, $url): void { $recipients->each(function ($recipient) use ($label, $record, $url): void { FilamentNotification::make() ->title("Nuevo {$label} desde la web: {$record->name}") ->actions([ Action::make('view') ->button() ->label("Ver {$label}") ->url($url) ->markAsRead(), ]) ->icon(Heroicon::OutlinedUserPlus) ->iconColor('success') ->sendToDatabase($recipient); }); NotificationFacade::send( $recipients, new NewApiLeadNotification($label, $record->name, $url) ); }); } /** @return array{0: string, 1: string} */ private function resolveLabelAndUrl(Company|People $record): array { if ($record instanceof Company) { return ['empresa', $this->resolveUrl(\App\Filament\Resources\CompanyResource::class, $record)]; } return ['candidato', $this->resolveUrl(\App\Filament\Resources\PeopleResource::class, $record)]; } private function resolveUrl(string $resourceClass, Company|People $record): string { try { return $resourceClass::getUrl('view', ['record' => $record]); } catch (\Throwable) { return '#'; } } }