承接 vlados/laravel-unique-urls 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

vlados/laravel-unique-urls

Composer 安装命令:

composer require vlados/laravel-unique-urls

包简介

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

README 文档

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.

统计信息

  • 总下载量: 1.76k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 9
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-06-07

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固