vlados/laravel-unique-urls

A package for using and generating unique urls for each Eloquent model in Laravel

Fund package maintenance!
vlados

Installs: 1 573

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 1

Forks: 0

Open Issues: 1

pkg:composer/vlados/laravel-unique-urls

v2.1.0 2026-02-12 11:52 UTC

This package is auto-updated.

Last update: 2026-02-22 16:30:18 UTC


README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads PHP Insights PHPStan

Generate unique, prefix-free URLs for any Eloquent model — blogs, e-commerce, multi-language platforms.

PHP 8.2+ | Laravel 11, 12

Features

  • Auto-trim slashes to prevent 404 errors
  • Multi-language URLs (distinct slugs per locale, not just prefixes)
  • Automatic redirects when URLs change (301 by default)
  • Hierarchical URLs via parent relationships (e.g. category/product)
  • Livewire full-page component support (FQCN and SFC names)
  • Batch generation with progress tracking for large datasets
  • Slug validation and reserved-slug protection
  • urls:doctor command for configuration health checks

Installation

composer require vlados/laravel-unique-urls
php artisan vendor:publish --tag="laravel-unique-urls-migrations"
php artisan migrate

Quick Start

Add the trait to your model and define how URLs are built:

use Vlados\LaravelUniqueUrls\HasUniqueUrls;

class Product extends Model
{
    use HasUniqueUrls;

    public function urlStrategy($language, $locale): string
    {
        return Str::slug($this->name, '-', $locale);
    }

    public function urlHandler(): array
    {
        return [
            'controller' => ProductController::class,
            'method'     => 'view',
            'arguments'  => [],
        ];
    }
}

Register the catch-all route at the end of routes/web.php:

Route::get('{urlObj}', [\Vlados\LaravelUniqueUrls\LaravelUniqueUrlsController::class, 'handleRequest'])
    ->where('urlObj', '.*');

Access URLs on any model instance:

$product->relative_url;  // "my-product"
$product->absolute_url;  // "https://example.com/my-product"
$product->getSlug('en'); // slug for a specific language

Documentation

Changelog

See CHANGELOG.md for release history.

Contributing

This project follows Conventional Commits.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). See LICENSE.md for details.