Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Slug Generator Laravel Package

ausi/slug-generator

Generate clean, customizable slugs for URLs and filenames using PHP’s Transliterator (CLDR). Supports many scripts (Cyrillic, Greek, CJK), locale-aware conversions, configurable valid chars and delimiters, and consistent ASCII output via simple options.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Pros:

    • PHP 8.0 Support: Confirms compatibility with modern Laravel versions (Laravel 9+), resolving a critical risk from the stale maintenance concern. The package now aligns with the LTS PHP version, reducing technical debt.
    • CLDR Updates: Updated fallback transform rule sets from the Common Locale Data Repository (CLDR) improve slug consistency across locales, addressing edge cases in multilingual applications (e.g., cafécafe or café).
    • Type Safety: Fixes for PHPStan issues suggest better maintainability and fewer runtime errors, particularly in strict mode environments.
    • Unicode/CLDR Synergy: Retains strong alignment with modern PHP applications requiring multilingual slugs (e.g., global SaaS, e-commerce, or CMS platforms).
    • Lightweight: Minimal dependencies remain unchanged, preserving the package’s efficiency.
  • Cons:

    • Still No Laravel-Specific Features: Lacks integration with Laravel’s service container, caching (e.g., Redis), or queue workers. This remains a gap for production-grade Laravel applications.
    • Limited Validation: No built-in checks for duplicate slugs or Laravel-specific validation rules (e.g., Rule::unique).
    • No PHP 8.2+ or 9.0 Support: While PHP 8.0 is supported, the release notes do not mention compatibility with newer PHP versions (8.2+), which may introduce risks for long-term projects.
    • Stale Maintenance: Last release in 2023 (v1.1.1) is still over a year old, raising concerns about compatibility with future PHP/Laravel updates.

Integration Feasibility

  • Core Use Cases:
    • Model Slugs: Ideal for replacing Str::slug() with SlugGenerator for consistent Unicode handling in Eloquent models.
    • API Endpoints: Suitable for generating slugs for dynamic routes (e.g., /products/{slug}) with improved locale-aware normalization.
    • SEO Optimization: Ensures slugs are URL-friendly across languages, addressing a key pain point in global applications.
  • Anti-Patterns:
    • Avoid using for non-URL contexts (e.g., filenames) without additional sanitization.
    • Not suitable for real-time collision resolution (e.g., post-1, post-2). Requires manual DB validation or integration with spatie/laravel-sluggable.

Technical Risk

Risk Area Mitigation Strategy
PHP 8.2+/9.0 Compatibility Test with php -d intl.enable=true and validate against Laravel 10/11. Monitor for deprecation warnings.
Deprecated APIs Check for warnings in symfony/polyfill-* dependencies; consider pinning versions.
Performance Bottlenecks Benchmark against Str::slug() for high-volume use (e.g., 10K+ slugs/sec). Profile with Xdebug if latency is critical.
Locale-Specific Issues Validate edge cases (e.g., Thai, Arabic scripts) with SlugGenerator::create('text', 'th'). Test CLDR updates for regressions.
Dependency Bloat Audit composer why-not ausi/slug-generator to ensure no conflicts with existing packages.
Type Safety Leverage PHPStan in CI to catch type-related issues early.

Key Questions

  1. Does the package support PHP 8.2+ or 9.0?
    • Action: Test with php -v 8.2.0 and 8.3.0 to confirm compatibility. If issues arise, consider forking or patching.
  2. How do the CLDR updates affect existing slugs?
    • Test: Compare outputs for critical locales (e.g., SlugGenerator::create('café', 'fr') vs. SlugGenerator::create('cafe', 'fr')).
  3. Can it be integrated with Laravel’s service container?
    • Workaround: Manually bind or use a facade, but this remains a gap for dependency injection.
  4. Is there a way to cache generated slugs (e.g., Redis)?
    • Workaround: Implement a decorator pattern or middleware to cache slugs per request.
  5. Does it integrate with Laravel’s validation rules (e.g., Rule::unique)?
    • Workaround: Use spatie/laravel-sluggable or custom validation logic.

Integration Approach

Stack Fit

  • Laravel Ecosystem:
    • Eloquent Models: Pair with spatie/laravel-sluggable for automatic slug generation/updates. The CLDR updates improve consistency for multilingual content.
      use Spatie\Sluggable\HasSlug;
      use Ausi\SlugGenerator\SlugGenerator;
      
      class Post extends Model implements HasSlug {
          public function getSlugOptions(): array {
              return ['generator' => fn($title) => SlugGenerator::create($title)];
          }
      }
      
    • API Routes: Use for dynamic slugs in Route::get('{slug}', ...) with middleware to validate slugs (e.g., reject non-ASCII if needed).
    • Form Requests: Replace Str::slug() in prepareForValidation with SlugGenerator for consistent normalization.
  • Non-Laravel PHP:
    • Standalone scripts or Symfony apps can use the generator directly via Composer, with the added benefit of PHP 8.0+ support.

Migration Path

  1. Assessment Phase:
    • Audit existing slug generation logic (e.g., Str::slug(), custom functions).
    • Identify high-impact areas (e.g., product listings, blog posts) and test CLDR updates for regressions.
  2. Pilot Phase:
    • Replace Str::slug() in a single model (e.g., Post) and test with multilingual content.
    • Compare output with current slugs (e.g., cafécafe vs. café) and document changes.
  3. Full Rollout:
    • Update all slug-related logic to use SlugGenerator.
    • Add middleware to validate slugs in routes (e.g., enforce ASCII-only if required).
  4. Fallback Plan:
    • Maintain a slug_v1 and slug_v2 column during transition if backward compatibility is critical.
    • Implement a feature flag to toggle between old and new slug generation logic.

Compatibility

Component Compatibility Notes
PHP 8.0+ Officially supported; test PHP 8.2+ for compatibility.
Laravel 9/10 No known conflicts, but verify intl extension is loaded.
PHP 9.0 Unconfirmed; test with php -v 9.0.0 if targeting future-proofing.
MySQL/PostgreSQL Ensure slug columns use TEXT or VARCHAR(255) (Unicode support).
Existing Slugs Run a migration to update old slugs if CLDR normalization rules differ (e.g., ée).

Sequencing

  1. Phase 1: Core Models
    • Migrate Post, Product, Category models to use SlugGenerator and validate CLDR changes.
  2. Phase 2: API Endpoints
    • Update routes and controllers to handle new slug formats, including validation middleware.
  3. Phase 3: Frontend
    • Adjust URL generation in Blade templates or JavaScript (e.g., window.location.pathname).
  4. Phase 4: Analytics
    • Monitor slug-related 404s (e.g., old vs. new formats) and implement redirects if needed.
  5. Phase 5: Performance Testing
    • Benchmark slug generation under load (e.g., 10K+ requests/sec) and optimize if bottlenecks are found.

Operational Impact

Maintenance

  • Pros:
    • PHP 8.0 Support: Aligns with Laravel’s supported PHP versions, reducing long-term maintenance risks.
    • CLDR Updates: Improves slug consistency and reduces edge-case bugs in multilingual applications.
    • Type Safety: Fixes for PHPStan issues suggest better stability and fewer runtime errors.
    • MIT License: No vendor lock-in; easy to fork or replace if needed.
  • Cons:
    • Still Stale Maintenance: Last release in 2023 (v1.1.1) may not keep pace with PHP 9.0+ or Laravel 11+.
    • No Laravel-Specific Features: Requires manual integration for caching, queues, or service container support.
    • Limited Documentation: Supplement internal docs for custom rules, troubleshooting, and CLDR edge cases.
  • Recommendations:
    • Set up a composer.json script to test the
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
make-dev/orca
dmstr/symfony-system-resources-bundle
dmstr/symfony-job-queue-bundle
dmstr/openapi-json-schema-bundle
dmstr/keycloak-security-bundle
dmstr/doctrine-audit-log-bundle
dmstr/api-platform-utils-bundle
dmstr/api-configuration-bundle
chrisdev/ux-components
baks-dev/finances
emuniq/filament-browser-notifications
syriable/filament-translator
hungnm28/livewire-form
wenprise/eloquent
crudly/encrypted
fadion/bouncy
cuci/prototurk-sdk
gos/pubsub-router-bundle
cuci/prototurk-sdk-symfony
clementtalleu/easyadmin-markdown-bundle