PHPackages                             jourdon/sluggable - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. jourdon/sluggable

ActiveLibrary[Database &amp; ORM](/categories/database)

jourdon/sluggable
=================

Easy create slug for your Eloquent models in Laravel

1.0(7y ago)9342MITPHP

Since Aug 31Pushed 7y ago1 watchersCompare

[ Source](https://github.com/jourdon/laravel-sluggable)[ Packagist](https://packagist.org/packages/jourdon/sluggable)[ RSS](/packages/jourdon-sluggable/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependencies (2)Versions (2)Used By (0)

laravel-Sluggable
=================

[](#laravel-sluggable)

[![Latest Stable Version](https://camo.githubusercontent.com/5aa9e8686a4b842ab77578eeb7decf9eda5addfc4ca06926787882970dc5d281/68747470733a2f2f706f7365722e707567782e6f72672f6a6f7572646f6e2f736c75676761626c652f762f737461626c65)](https://packagist.org/packages/jourdon/sluggable)[![Total Downloads](https://camo.githubusercontent.com/70e219292e6743e7180789001028d21fa7bc143c415f79a90d253c59ea60ded7/68747470733a2f2f706f7365722e707567782e6f72672f6a6f7572646f6e2f736c75676761626c652f646f776e6c6f616473)](https://packagist.org/packages/jourdon/sluggable)[![Latest Unstable Version](https://camo.githubusercontent.com/877bae44399afa021564062aa8fdd6dbf04763d83748597ff03e00dd951c3b36/68747470733a2f2f706f7365722e707567782e6f72672f6a6f7572646f6e2f736c75676761626c652f762f756e737461626c65)](https://packagist.org/packages/jourdon/sluggable)[![License](https://camo.githubusercontent.com/315c6f27846c2b5bb592b4337bfff92a1ec058d43e3c1adefb6017f15ee84b7b/68747470733a2f2f706f7365722e707567782e6f72672f6a6f7572646f6e2f736c75676761626c652f6c6963656e7365)](https://packagist.org/packages/jourdon/sluggable)

说明
--

[](#说明)

我的博客有很多文章，很多分类，他们的链接是这样的

```
//文章
http://example.com/post/1
http://example.com/post/2
//分类
http://example.com/category/1
http://example.com/category/2

```

这看起来非常不友好，我希望将后面的id换成文章的村里或者分类的名称，这样看起来比较友好，从链接就能看出来文章的内容，对搜索引擎也比较友好，像这样：

```
http://example.com/post/php-is-the-best-language-in-the-world
http://example.com/post/yes-i-think-so
//分类
http://example.com/category/php
http://example.com/category/laravel

```

你只需要安装本扩展包，你不需要另外做什么，它会自动帮你搞定，可以根据你的Eloquent模型生成相应的slug，让你的url更加的友好。

\##要求

- PHP版本: 7.1+
- laravel版本:5.5+

安装
--

[](#安装)

1、 使用 Composer 安装:

```
composer require jourdon/sluggable
```

2、 配置

> 本扩展包本身不需要配置文件,也无需配置，但本扩展包依赖于 [laravel-slug](https://github.com/jourdon/laravel-slug) ,所以需要导出`laravel-slug` 的配置文件，具体请前往 [laravel-slug](https://github.com/jourdon/laravel-slug) 查看并配置。

3、 添加Slug字段

你的数据表中需要有slug字段，执行下面的命令生成迁移文件，以Post模型为例:

```
php artisan jourdon:make_slug Post
```

4、 运行迁移

```
php artisan migrate
```

> 如果你的数据表中已经有slug字段，请忽略 3，4

5、将Eloquent模型的slug加入缓存，注意这里，Laravel默认的Model目录在app下，假如你的Eloquent模型都放在app/models目录下，你需要在Eloquent模型前加上Models/

```
php artisan jourdon:make_cache Models/Post
```

使用
--

[](#使用)

还是以Post模型为例，我们需要使用SlugTrait

```
use Jourdon\Sluggable\Traits\SlugTrait;

class Post extends Model
{
    use SlugTrait;
    .
    .
    .
}
```

如果你还需要将Category的URL也变得这么漂亮，只需要重复3，4，5即可。

### OK. 已经完成了，去看看你的链接吧，

[](#ok-已经完成了去看看你的链接吧)

###  Health Score

29

—

LowBetter than 59% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community5

Small or concentrated contributor base

Maturity62

Established project with proven stability

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

2813d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/c00025001b5a58f2bf19bbe21f240e47e751cb29b8e53e11ded323623bfe37b7?d=identicon)[jourdon](/maintainers/jourdon)

---

Tags

laravellaravel-sluggableslugsluggablesluglaraveleloquentsluggablemodels

### Embed Badge

![Health badge](/badges/jourdon-sluggable/health.svg)

```
[![Health](https://phpackages.com/badges/jourdon-sluggable/health.svg)](https://phpackages.com/packages/jourdon-sluggable)
```

###  Alternatives

[cviebrock/eloquent-sluggable

Easy creation of slugs for your Eloquent models in Laravel

4.0k13.6M253](/packages/cviebrock-eloquent-sluggable)[anourvalar/eloquent-serialize

Laravel Query Builder (Eloquent) serialization

11320.2M21](/packages/anourvalar-eloquent-serialize)[stayallive/laravel-eloquent-observable

Register Eloquent model event listeners just-in-time directly from the model.

2928.9k7](/packages/stayallive-laravel-eloquent-observable)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
