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

Persian Slug Laravel Package

pishran/persian-slug

pishran/persian-slug یک پکیج ساده برای ساخت اسلاگ استاندارد با پشتیبانی کامل از فارسی است. ورودی‌های فارسی و انگلیسی را به اسلاگ‌های خوانا تبدیل می‌کند (مثل سلام دنیا → سلام-دنیا، Hello world → hello-world). نصب با Composer.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Lightweight & Focused: The package is a pure utility for generating Persian-friendly slugs, making it a low-overhead addition to any Laravel/PHP application. It does not introduce new dependencies or complex abstractions, aligning well with modular architectures (e.g., service layers, value objects).
  • Domain-Specific: Ideal for applications requiring Persian/Arabic SEO-friendly URLs (e.g., news sites, e-commerce with Farsi content, or multilingual platforms). Poor fit for projects where slugs are non-critical or non-Persian.
  • Composability: Can be injected as a service (e.g., via Laravel’s App\Services\SlugService) or used ad-hoc in controllers/models, adhering to SOLID principles.

Integration Feasibility

  • Laravel Native: Works seamlessly with Laravel’s eloquent models (via accessors/mutators) or form requests (e.g., slug field generation).
  • PHP Interoperability: Pure PHP (no JS/Node dependencies), ensuring compatibility with legacy systems or headless APIs.
  • Database Agnostic: Slugs can be stored in any database (MySQL, PostgreSQL, etc.) with standard VARCHAR fields.

Technical Risk

  • Character Handling: Risk of edge cases with mixed scripts (e.g., "Hello سلام" → hello-سلام vs. hello-salam). Requires testing for non-standard inputs.
  • Performance: Minimal overhead (O(n) for string processing), but bulk operations (e.g., backfilling slugs) may need batching.
  • Deprecation: Last release in 2023; monitor for abandonware (MIT license mitigates risk but lacks active maintenance).

Key Questions

  1. Use Case Validation:
    • Is Persian slug generation a core requirement (e.g., 80%+ of content is Farsi) or a niche feature?
    • Are there existing slug packages (e.g., spatie/laravel-sluggable) already in use?
  2. Customization Needs:
    • Does the default behavior (e.g., hyphenation, character replacement) meet requirements, or are custom rules needed?
  3. Testing:
    • How will edge cases (e.g., emojis, mixed scripts) be handled in automated tests?
  4. Alternatives:
    • Compare with cocur/slug-generator (supports more locales) or custom logic if the package is abandoned.

Integration Approach

Stack Fit

  • Laravel Ecosystem:
    • Eloquent Models: Use accessors to auto-generate slugs:
      public function getSlugAttribute(): string
      {
          return str_slug_persian($this->title);
      }
      
    • Form Requests: Validate/sanitize slugs via Illuminate\Validation\Rule:
      'slug' => ['required', Rule::unique('posts')->ignore($post)],
      
    • APIs: Integrate into resource controllers or DTOs for consistency.
  • Non-Laravel PHP:
    • Use as a standalone utility in procedural or framework-agnostic apps (e.g., Symfony, custom MVC).

Migration Path

  1. Incremental Adoption:
    • Start with new features (e.g., Persian blog posts) before retrofitting existing data.
    • Use database migrations to add slug columns:
      php artisan make:migration add_slug_to_posts_table --table=posts
      
  2. Backfilling:
    • Batch-update slugs via Artisan commands or queued jobs:
      Post::chunk(100, function ($posts) {
          foreach ($posts as $post) {
              $post->update(['slug' => str_slug_persian($post->title)]);
          }
      });
      
  3. Fallback Strategy:
    • Implement a hybrid approach (e.g., fallback to str_slug for non-Persian content) if the package is deprecated.

Compatibility

  • PHP Version: Supports PHP 7.4+ (check Laravel version compatibility).
  • Dependencies: Zero external dependencies beyond Composer autoloader.
  • Conflict Risk: Low—package uses a unique namespace (pishran\PersianSlug).

Sequencing

  1. Phase 1: Install and test in a staging environment.
  2. Phase 2: Integrate into models/controllers with unit tests.
  3. Phase 3: Deploy with feature flags for gradual rollout.
  4. Phase 4: Monitor for performance regressions (e.g., slug generation in bulk operations).

Operational Impact

Maintenance

  • Low Effort: Minimal maintenance expected (MIT license, no active updates).
  • Monitoring: Set up error tracking (e.g., Sentry) for edge cases in slug generation.
  • Documentation: Update internal docs to reflect Persian slug conventions (e.g., "use hyphens, not underscores").

Support

  • Troubleshooting:
    • Common issues: character encoding (UTF-8), collision handling (duplicate slugs).
    • Debug with dd(str_slug_persian($input)) to inspect outputs.
  • Community: Limited (5 stars, no dependents); rely on GitHub issues or custom forks if needed.

Scaling

  • Performance:
    • Single-threaded: No scalability bottlenecks for typical use cases.
    • High-volume: For millions of slugs, consider caching (e.g., Redis) or precomputing slugs during content creation.
  • Database:
    • Index slug columns for SEO and uniqueness checks:
      Schema::table('posts', function (Blueprint $table) {
          $table->string('slug')->unique();
      });
      

Failure Modes

Failure Scenario Impact Mitigation
Package abandonment Broken slugs in production Fork or replace with cocur/slug-generator
Character encoding issues Corrupted slugs (e.g., "سلام" → "????") Validate UTF-8 input, add fallback logic
Duplicate slugs SEO conflicts, 404s Use UUIDs or append IDs as suffixes
Performance degradation Slow slug generation in bulk ops Batch processing, caching

Ramp-Up

  • Onboarding:
    • 1-2 hours for basic integration (Composer install + model accessor).
    • 1 day for full testing (edge cases, performance).
  • Team Training:
    • Document slug conventions (e.g., "Persian titles must use hyphens").
    • Train devs on debugging slug generation (e.g., tinker tests).
  • Rollback Plan:
    • Maintain a backup slug column (e.g., slug_old) during migration.
    • Use feature toggles to disable Persian slugs if issues arise.
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.
sentix/ai-chatbot
terminal42/code-quality-tools
codifyo/ts-generator-bundle
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky