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

Laravel Persian Slug Laravel Package

pishran/laravel-persian-slug

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Use Case Alignment: Ideal for Persian-language applications requiring SEO-friendly, human-readable URLs (e.g., blogs, e-commerce, or content platforms in Farsi/Arabic). Leverages Laravel’s Eloquent ORM for seamless integration with existing model structures.
  • Design Pattern: Follows Laravel’s service provider and trait-based architecture, aligning with Spatie’s laravel-sluggable (a well-established package). Minimal intrusion into core application logic.
  • Localization Support: Addresses a niche but critical gap for Persian/Dari/Arabic markets, where Latin-character slugs (e.g., post-123) are less intuitive than localized alternatives (e.g., مقاله-اول).

Integration Feasibility

  • Dependencies:
    • Primary: Requires spatie/laravel-sluggable (≥2.0 for Laravel 8+). This is a low-risk dependency, widely adopted (10k+ stars) and actively maintained.
    • Secondary: PHP 8.0+ and Laravel 7/8/9. Compatibility with newer Laravel versions (e.g., 10) may need validation.
  • Database Impact:
    • Adds a slug column to target tables (if not pre-existing). Schema migrations are handled via spatie/laravel-sluggable, reducing customization overhead.
    • Conflict Risk: Potential for slug collisions if generateSlugsFrom includes non-unique fields (e.g., duplicate titles). Mitigated by Spatie’s default collision handling (appends -2, -3, etc.).

Technical Risk

  • Localization Complexity:
    • Persian/Arabic slugs introduce challenges like:
      • Character Encoding: Right-to-left (RTL) text may require CSS/URL handling (e.g., ?dir=rtl or CSS unicode-bidi).
      • SEO Implications: Search engines may index RTL URLs differently. Test with tools like Google Search Console.
    • Validation: Ensure slugs comply with URL standards (e.g., no spaces, special chars replaced with hyphens).
  • Performance:
    • Slug generation is deferred to model events (e.g., saving). For high-write workloads, batch processing (e.g., Model::updateSlugs()) may be needed.
  • Backward Compatibility:
    • Laravel 7 support is via v1.4, but the package is abandoned (last release 2023-01-10). Risk of unpatched bugs or Laravel 10+ incompatibilities.

Key Questions

  1. Localization Strategy:
    • How will RTL URLs be handled in frontend frameworks (e.g., React/Vue)? Will you use a proxy route (e.g., /en/{slug}) or client-side RTL detection?
  2. Collision Handling:
    • Are duplicate slugs acceptable (e.g., for non-SEO routes), or must they be unique? Customize SlugOptions with doNotGenerateSlugsIfSlugIsEmpty() or unique().
  3. Testing:
    • Have you validated slug generation for edge cases (e.g., titles with emojis, mixed scripts like "Hello دنیا")?
  4. Maintenance:
    • Given the package’s stagnation, is a fork or custom implementation justified for long-term support?

Integration Approach

Stack Fit

  • Laravel Ecosystem:
    • Native Integration: Works out-of-the-box with Eloquent models, API resources, and Laravel’s routing system (e.g., Route::get('/posts/{slug}', ...)).
    • Frontend Agnostic: Slugs are generated server-side; frontend frameworks (e.g., Next.js, Nuxt) can consume them via API or SSR.
  • Non-Laravel Systems:
    • Limited Use: Not directly usable in non-Laravel PHP apps (e.g., Symfony). Would require rewriting the slug logic or abstracting it via a microservice.

Migration Path

  1. Prerequisites:
    • Ensure spatie/laravel-sluggable is installed (composer require spatie/laravel-sluggable).
    • Laravel 8+: Use pishran/laravel-persian-slug:^2.0.
    • Laravel 7: Use pishran/laravel-persian-slug:1.4 (but be aware of maintenance risks).
  2. Implementation Steps:
    • Step 1: Add the package and publish config (if needed):
      composer require pishran/laravel-persian-slug
      php artisan vendor:publish --provider="Pishran\LaravelPersianSlug\LaravelPersianSlugServiceProvider"
      
    • Step 2: Apply migrations for the slug column (if missing):
      php artisan migrate
      
    • Step 3: Integrate the trait into models:
      use HasPersianSlug;
      use Spatie\Sluggable\SlugOptions;
      
      class Post extends Model {
          use HasPersianSlug;
      
          public function getSlugOptions(): SlugOptions {
              return SlugOptions::create()
                  ->generateSlugsFrom('title')
                  ->saveSlugsTo('slug')
                  ->usingSeparator('-');
          }
      }
      
    • Step 4: Update routes/controllers to use the slug:
      Route::get('/posts/{slug}', [PostController::class, 'show']);
      
  3. Data Migration:
    • For existing records, use a seeder or artisan command to backfill slugs:
      Post::all()->each(function ($post) {
          $post->save(); // Triggers slug generation
      });
      

Compatibility

  • Laravel Versions:
    • Supported: 7 (v1.4), 8/9 (v2.0). Test thoroughly for Laravel 10.
    • Unsupported: Laravel <7 or >10 without adjustments.
  • Database:
    • Works with MySQL, PostgreSQL, SQLite. No vendor-specific SQL.
  • Customization:
    • Extend SlugOptions for advanced use cases (e.g., custom separators, field transformations):
      ->generateSlugsFrom(function () {
          return strtolower($this->title . ' ' . $this->category->name);
      })
      

Sequencing

  1. Phase 1: Pilot with non-critical models (e.g., blog posts).
  2. Phase 2: Integrate into high-traffic routes after validating slug uniqueness and SEO impact.
  3. Phase 3: Replace legacy slug logic (if any) with this package’s standardized approach.

Operational Impact

Maintenance

  • Package Risks:
    • Stagnation: No updates since 2023. Monitor for Laravel 10+ compatibility issues.
    • Mitigation: Fork the repo or implement a custom solution if critical bugs arise.
  • Dependency Updates:
    • spatie/laravel-sluggable is actively maintained (check for breaking changes).
  • Custom Logic:
    • Override HasPersianSlug methods if default behavior (e.g., collision handling) is insufficient.

Support

  • Documentation:
    • Gaps: README lacks examples for edge cases (e.g., mixed scripts, custom separators). Supplement with internal docs.
    • Spatie Docs: Refer to spatie/laravel-sluggable for advanced usage.
  • Community:
    • Limited activity (55 stars). Open issues on GitHub for critical bugs or feature requests.

Scaling

  • Performance:
    • Slug Generation: Minimal overhead during model saves. For bulk operations, consider:
      Post::chunk(100, function ($posts) {
          foreach ($posts as $post) {
              $post->save(); // Batch slug generation
          }
      });
      
    • Database Indexing: Add an index to the slug column for route resolution:
      Schema::table('posts', function (Blueprint $table) {
          $table->string('slug')->unique()->index();
      });
      
  • Caching:
    • Cache slugs in memory (e.g., Redis) if slugs are static and rarely updated.

Failure Modes

Scenario Impact Mitigation
Slug collision Duplicate URLs or 404s Use SlugOptions::unique() or custom logic.
RTL URL rendering issues Broken frontend layouts Test with RTL CSS frameworks (e.g., Tailwind).
Package incompatibility Breaks slug generation Fork or implement a fallback (e.g., manual slugging).
High write load Slow slug generation Batch processing or queue jobs.

Ramp-Up

  • Developer Onboarding:
    • Time Estimate: 1–2 hours to integrate into a single model.
    • Key Topics:
      • How `SlugOptions
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.
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui
babelqueue/php-sdk
facebook/capi-param-builder-php
babelqueue/symfony
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle