title(self::clean($finalTitle)) ->body(self::clean($finalBody)) ->success() ); } /** * Custom info notification. */ public static function info(string $title, string $body, ?string $formalTitle = null, ?string $formalBody = null): Notification { $finalTitle = self::getMessage($title, $formalTitle ?? $title); $finalBody = self::getMessage($body, $formalBody ?? $body); return self::applyStyle( self::make() ->title(self::clean($finalTitle)) ->body(self::clean($finalBody)) ->info() ); } /** * Custom warning notification. */ public static function warning(string $title, string $body, ?string $formalTitle = null, ?string $formalBody = null): Notification { $finalTitle = self::getMessage($title, $formalTitle ?? $title); $finalBody = self::getMessage($body, $formalBody ?? $body); return self::applyStyle( self::make() ->title(self::clean($finalTitle)) ->body(self::clean($finalBody)) ->warning() ); } /** * Custom danger notification. */ public static function danger(string $title, string $body, ?string $formalTitle = null, ?string $formalBody = null): Notification { $finalTitle = self::getMessage($title, $formalTitle ?? $title); $finalBody = self::getMessage($body, $formalBody ?? $body); return self::applyStyle( self::make() ->title(self::clean($finalTitle)) ->body(self::clean($finalBody)) ->danger() ); } /** * Apply the user's selected style to the notification. */ protected static function applyStyle(Notification $notification): Notification { if (self::getNotifStyle() === NotifStyle::Formal) { $notification->icon(null); } return $notification; } /** * Get the current user's notification style preference. */ public static function getNotifStyle(): NotifStyle { try { /** @var \App\Models\User $user */ $user = Auth::user(); return $user?->settings?->notif_style ?? NotifStyle::Cheerful; } catch (\Throwable $e) { return NotifStyle::Cheerful; } } /** * Get message based on the user's notification style preference. */ public static function getMessage(string $cheerful, string $formal): string { return self::getNotifStyle() === NotifStyle::Cheerful ? $cheerful : $formal; } /** * Strip emojis if the notification style is formal. */ public static function clean(string $text): string { if (self::getNotifStyle() === NotifStyle::Formal) { // Comprehensive regex to remove emojis and symbols $regex = '/[\x{1F600}-\x{1F64F}\x{1F300}-\x{1F5FF}\x{1F680}-\x{1F6FF}\x{2600}-\x{26FF}\x{2700}-\x{27BF}\x{1F900}-\x{1F9FF}\x{1F1E0}-\x{1F1FF}]/u'; return trim(preg_replace($regex, '', $text)); } return $text; } }