PHPackages                             taylornetwork/model-slugger - 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. taylornetwork/model-slugger

ActiveLibrary

taylornetwork/model-slugger
===========================

Automatically add slugs to eloquent models

1.0.1(8y ago)033PHPPHP &gt;=5.4.0

Since Apr 8Pushed 8y ago1 watchersCompare

[ Source](https://github.com/taylornetwork/ModelSlugger)[ Packagist](https://packagist.org/packages/taylornetwork/model-slugger)[ RSS](/packages/taylornetwork-model-slugger/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (2)Dependencies (2)Versions (3)Used By (0)

ModelSlugger
============

[](#modelslugger)

Install
-------

[](#install)

Using Composer

```
$ composer require taylornetwork/model-slugger
```

Usage
-----

[](#usage)

In a class that extends `Illuminate\Database\Eloquent\Model` add the `TaylorNetwork\ModelSlugger\ModelSlugger` trait.

This will require you to define the `sluggerConfig()` function which returns an array with minimum options being `['source' => 'model field to make slug from']`

```
// app/ExampleModel.php

namespace App;

use Illuminate\Database\Eloquent\Model;
use TaylorNetwork\ModelSlugger\ModelSlugger;

class ExampleModel extends Model
{
	use ModelSlugger;

	public function sluggerConfig()
	{
		return [
			'source' => 'name',
		];
	}
}
```

Where `name` would be converted to a slug and placed into the column `slug` by default

Bind slug to route
------------------

[](#bind-slug-to-route)

You can bind the routes in your application to the slug rather than ID by adding

```
protected $sluggerRouteModelBind = true;
```

To your model, it will cause the routes to be looked up using the slug column.

Unique
------

[](#unique)

To make all slugs unique add `'unique' => 'all'` to the config array either in the model or in `config/slugger.php`

```
// app/ExampleModel.php

public function sluggerConfig()
{
  return [
    'source' => 'name',
    'unique' => 'all',
  ];
}
```

Unique to a Parent
------------------

[](#unique-to-a-parent)

If you want slugs to only be unique based on a parent class, add `'unique' => 'parent', 'parent' => 'App\ParentClassName'` to the model or `config/slugger.php`

For example you have a `App\User` model and a `App\TodoList` model where the a user can have many todo lists each with slugs. If we set the config to `unique => all` and every user makes a todo list named `'my todo list'` the slugs will become increasingly long as they become unique.

To avoid this you can make the slugs unique if they are from the same parent.

```
// app/TodoList.php

public function sluggerConfig()
{
  return [
    'source' => 'name',
    'unique' => 'parent',
    'parent' => 'App\User',
  ];
}
```

### Slugger Route Model Bind with Unique to a Parent

[](#slugger-route-model-bind-with-unique-to-a-parent)

To accomplish route model binding you will need to add the code to find only slugs with the correct parent to your `App\Providers\RouteServiceProvider` class

For example

```
public function boot()
{
    Route::bind('user', function ($value) {
        return App\User::findOrFail($value); // Code to find by ID or slug
    });

    Route::bind('todoList', function ($slug, $route) {
        // $route->parameter('user') will return an instance of App\User
        return $route->parameter('user')->todoLists()->where('slug', $slug)->firstOrFail();
    });

    parent::boot();
}
```

Credits
-------

[](#credits)

- Main Author: [Sam Taylor](https://github.com/taylornetwork)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

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

Every ~378 days

Total

2

Last Release

2940d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/83340094473f0bf5b2cf062bf394df221a52a30aa0e21cd0a77302977d6393ce?d=identicon)[samueljtaylor](/maintainers/samueljtaylor)

---

Top Contributors

[![samyrataylor](https://avatars.githubusercontent.com/u/15961687?v=4)](https://github.com/samyrataylor "samyrataylor (4 commits)")

### Embed Badge

![Health badge](/badges/taylornetwork-model-slugger/health.svg)

```
[![Health](https://phpackages.com/badges/taylornetwork-model-slugger/health.svg)](https://phpackages.com/packages/taylornetwork-model-slugger)
```

###  Alternatives

[cviebrock/eloquent-sluggable

Easy creation of slugs for your Eloquent models in Laravel

4.0k13.6M253](/packages/cviebrock-eloquent-sluggable)[fumeapp/modeltyper

Generate TypeScript interfaces from Laravel Models

196277.9k](/packages/fumeapp-modeltyper)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

255.2k](/packages/aedart-athenaeum)

PHPackages © 2026

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