Generate unique, prefix-free URLs for any Eloquent model — blogs, e-commerce, multi-language platforms.
PHP 8.2+ | Laravel 11, 12
- 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:doctorcommand for configuration health checks
composer require vlados/laravel-unique-urls
php artisan vendor:publish --tag="laravel-unique-urls-migrations"
php artisan migrateAdd 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- Configuration — config options and defaults
- Usage — model setup, routes, multi-language, Livewire
- Bulk Operations — batch generation, global toggles, performance
- Artisan Commands —
urls:generateandurls:doctor - Testing — assertion helpers and example tests
- Troubleshooting — common issues and fixes
See CHANGELOG.md for release history.
This project follows Conventional Commits.
Please review our security policy on how to report security vulnerabilities.
The MIT License (MIT). See LICENSE.md for details.