spatie/laravel-sluggable 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

spatie/laravel-sluggable

Composer 安装命令:

composer require spatie/laravel-sluggable

包简介

Generate slugs when saving Eloquent models

README 文档

README

Logo for laravel-sluggable

Generate slugs when saving Eloquent models

Latest Version on Packagist MIT Licensed GitHub Workflow Status Total Downloads

This package generates a unique slug for any Eloquent model whenever it is created or updated. Add a #[Sluggable] attribute to the model and the package handles the rest.

use Spatie\Sluggable\Attributes\Sluggable;

#[Sluggable(from: 'title', to: 'slug')]
class Post extends Model
{
}

$post = Post::create(['title' => 'activerecord is awesome']);
$post->slug; // "activerecord-is-awesome"

For features that need closures (custom source callables, scoped uniqueness, conditional skip, custom suffix generators) use the HasSlug trait with a getSlugOptions() method instead.

Highlights

  • Unique slugs out of the box, with a configurable -1, -2, ... suffix on collisions.
  • Self-healing URLs: route keys that combine the slug with the primary key (hello-world-5) so renaming a model never breaks an existing link. Stale slugs return a 308 redirect to the canonical URL.
  • Translatable slugs through HasTranslatableSlug and spatie/laravel-translatable.
  • Overridable actions: swap the slug generator or the self-healing URL logic for your own class via a config file.
  • Laravel Boost skill bundled with the package, so AI assistants know how to scaffold sluggable models in your project. Boost discovers it automatically once both packages are installed.

Self-healing URLs combine the slug with the primary key. The HasSlug trait is required alongside the attribute, because it overrides Eloquent's route key and route binding methods.

#[Sluggable(from: 'title', to: 'slug', selfHealing: true)]
class Post extends Model
{
    use HasSlug;
}

// /posts/hello-world-5   → 200
// /posts/old-title-5     → 308 to /posts/hello-world-5

Spatie is a web design agency based in Antwerp, Belgium. You'll find an overview of all our open source projects on our website.

Support us

We invest a lot of resources into creating best in class open source packages. You can support us by buying one of our paid products.

We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on our contact page. We publish all received postcards on our virtual postcard wall.

Documentation

All documentation is available on our documentation site.

Installation

composer require spatie/laravel-sluggable

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you've found a bug regarding security please mail security@spatie.be instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

spatie/laravel-sluggable 适用场景与选型建议

spatie/laravel-sluggable 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 12.75M 次下载、GitHub Stars 达 1.55k, 最近一次更新时间为 2015 年 12 月 24 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「translatable」 「slug」 「laravel」 「eloquent」 「spatie」 「slugs」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 spatie/laravel-sluggable 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 spatie/laravel-sluggable 我们能提供哪些服务?
定制开发 / 二次开发

基于 spatie/laravel-sluggable 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 12.75M
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1571
  • 点击次数: 41
  • 依赖项目数: 290
  • 推荐数: 0

GitHub 信息

  • Stars: 1545
  • Watchers: 16
  • Forks: 190
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-12-24