PHPackages                             paxha/laravel-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. [Utility &amp; Helpers](/categories/utility)
4. /
5. paxha/laravel-sluggable

ActiveLaravel[Utility &amp; Helpers](/categories/utility)

paxha/laravel-sluggable
=======================

This package provides an event that will generate a unique slug when saving or creating any Eloquent model.

v2.2.0(5y ago)24.0k21MITPHPPHP ^7.2|^8.0

Since Dec 25Pushed 5y ago1 watchersCompare

[ Source](https://github.com/paxha/laravel-sluggable)[ Packagist](https://packagist.org/packages/paxha/laravel-sluggable)[ RSS](/packages/paxha-laravel-sluggable/feed)WikiDiscussions master Synced yesterday

READMEChangelog (7)Dependencies (2)Versions (11)Used By (1)

[![Build Status](https://camo.githubusercontent.com/21c5c9adcc09c1c5419712722e65b56bd2a82efa4cbb7960e5f254a296804dba/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f70617868612f6c61726176656c2d736c75676761626c652f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/paxha/laravel-sluggable)[![StyleCI](https://camo.githubusercontent.com/aabe78333ffe4a19952e2e43e57560ee6e906ed3c16603a052240deb2a9ebc11/68747470733a2f2f6769746875622e7374796c6563692e696f2f7265706f732f3233303037393330322f736869656c643f6272616e63683d6d6173746572)](https://github.styleci.io/repos/230079302)[![Total Downloads](https://camo.githubusercontent.com/c300cb98164c1e394bf3b8b860f38c3fcde967942b32cc93d4573f3e556be9b8/68747470733a2f2f706f7365722e707567782e6f72672f70617868612f6c61726176656c2d736c75676761626c652f642f746f74616c2e7376673f666f726d61743d666c61742d737175617265)](https://packagist.org/packages/paxha/laravel-sluggable)[![Latest Stable Version](https://camo.githubusercontent.com/f4cf4f7b2bfa44ed51a577d890fd0ec5307739117c747690eadccbe551628ef6/68747470733a2f2f706f7365722e707567782e6f72672f70617868612f6c61726176656c2d736c75676761626c652f762f737461626c652e7376673f666f726d61743d666c61742d737175617265)](https://packagist.org/packages/paxha/laravel-sluggable)[![License](https://camo.githubusercontent.com/5969a3682a32c136b3a3428f8bb624e0108cefafc6e9c4cdef5cce7c634b80fd/68747470733a2f2f706f7365722e707567782e6f72672f70617868612f6c61726176656c2d736c75676761626c652f6c6963656e73652e7376673f666f726d61743d666c61742d737175617265)](https://packagist.org/packages/paxha/laravel-sluggable)

Laravel Slug Generator
======================

[](#laravel-slug-generator)

Introduction
------------

[](#introduction)

This package provides an event that will generate a unique slug when saving or creating any Eloquent model.

Installation
------------

[](#installation)

```
composer require paxha/laravel-sluggable

```

Usage
-----

[](#usage)

- [Getting Started](#getting-started)
- [Examples](#examples)

### Getting Started

[](#getting-started)

Consider the following table schema for hierarchical data:

```
Schema::create('users', function (Blueprint $table) {
    $table->increments('id');
    $table->string('name');
    $table->string('slug')->unique();
});
```

Use the `Sluggable` trait in your model to work with slug:

```
class User extends Model
{
    use \Sluggable\Traits\Sluggable;
}
```

By default, the trait expects three things

1. slugFrom(): array (optional) if you using `name` column
2. slugSaveTo(): string (optional) if you using `slug` column
3. separator(): string (optional) default `-`

You can overriding it as well `slugFrom()`, `slugSaveTo()` and `separator()`:

```
class User extends Model
{
    use \Sluggable\Traits\Sluggable;

    public static function slugFrom()
    {
        return ['name']; // or return ['first_name', 'last_name'];
    }

    public static function slugSaveTo()
    {
        return 'slug'; // or return ['user_slug'];
    }

    public static function separator()
    {
        return '-'; // or return '_';
    }
}
```

### Examples

[](#examples)

#### Example A

[](#example-a)

##### Database

[](#database)

```
Schema::create('users', function (Blueprint $table) {
    $table->increments('id');
    $table->string('first_name');
    $table->string('last_name');
    $table->string('slug')->unique();
});
```

##### Model

[](#model)

```
class User extends Model
{
    use \Sluggable\Traits\Sluggable;

    protected $fillable = [
        'first_name', 'last_name',
    ];

    public static function slugFrom()
    {
        return ['first_name', 'last_name'];
    }
}
```

##### Create User

[](#create-user)

```
User::create([
    'first_name' => 'John',
    'last_name' => 'Doe'
]);

// or

$user = new User();
$user->first_name = 'John';
$user->last_name = 'Doe';
$user->save();
```

##### Output

[](#output)

```
{
    'first_name': 'John',
    'last_name': 'Doe',
    'slug': 'john-doe',
}
```

#### Example B

[](#example-b)

##### Table

[](#table)

```
Schema::create('users', function (Blueprint $table) {
    $table->increments('id');
    $table->string('name');
    $table->string('user_slug')->unique();
});
```

##### Model

[](#model-1)

```
class User extends Model
{
    use \Sluggable\Traits\Sluggable;

    protected $fillable = [
        'name',
    ];

    public static function slugSaveTo()
    {
        return ['user_slug'];
    }

    public static function separator()
    {
        return '_';
    }
}
```

##### Create User

[](#create-user-1)

```
User::create([
    'name' => 'John Doe'
]);

// or

$user = new User();
$user->name = 'John Doe';
$user->save();
```

##### Output

[](#output-1)

```
{
    'name': 'John Doe',
    'user_slug': 'john_doe',
}
```

License
-------

[](#license)

This is open-sourced laravel library licensed under the [MIT license](https://opensource.org/licenses/MIT).

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity21

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity68

Established project with proven stability

 Bus Factor1

Top contributor holds 87.5% 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 ~59 days

Recently: every ~89 days

Total

7

Last Release

1972d ago

Major Versions

v1.2.0 → v2.0.02020-10-07

PHP version history (2 changes)v1.0PHP ^7.2

v2.2.0PHP ^7.2|^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/2816953f287ca302f12d59f94de4e90cd6cb5d2ba1f6eaa462045c2670969ea0?d=identicon)[paxha](/maintainers/paxha)

---

Top Contributors

[![paxha](https://avatars.githubusercontent.com/u/38579192?v=4)](https://github.com/paxha "paxha (21 commits)")[![abidaslam](https://avatars.githubusercontent.com/u/47294944?v=4)](https://github.com/abidaslam "abidaslam (2 commits)")[![pasha-my-glu](https://avatars.githubusercontent.com/u/68679138?v=4)](https://github.com/pasha-my-glu "pasha-my-glu (1 commits)")

---

Tags

laravellaravel-packagelaravel-sluggableslugsluggablelaravellaravel-packagesluggablelaravel-sluggableslug-generatorlaravel\_slug\_generator

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[realrashid/sweet-alert

Laravel Sweet Alert Is A Package For Laravel Provides An Easy Way To Display Alert Messages Using The SweetAlert2 Library.

1.2k2.9M21](/packages/realrashid-sweet-alert)[imanghafoori/laravel-nullable

A package to help you write expressive defensive code in a functional manner

151423.7k6](/packages/imanghafoori-laravel-nullable)[josezenem/laravel-slugidable

A package for Laravel that creates slugs for Eloquent models based on title and ID

1159.5k](/packages/josezenem-laravel-slugidable)[djunehor/laravel-bible

Laravel package to fetch from the Holy Bible

182.8k](/packages/djunehor-laravel-bible)[paxha/laravel-reportable

This Laravel Eloquent extension provides record according to dates using models.

111.2k](/packages/paxha-laravel-reportable)

PHPackages © 2026

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