PHPackages                             kodooy/laravel-slug-generator - 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. kodooy/laravel-slug-generator

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

kodooy/laravel-slug-generator
=============================

Laravel package for automatic slug generation using traits

v1.0.1(9mo ago)02MITPHPPHP ^8.1

Since Jul 31Pushed 9mo agoCompare

[ Source](https://github.com/kodooy/laravel-slug-generator)[ Packagist](https://packagist.org/packages/kodooy/laravel-slug-generator)[ RSS](/packages/kodooy-laravel-slug-generator/feed)WikiDiscussions main Synced 1mo ago

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

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

[](#slug-generator-laravel-package)

A Laravel package that provides automatic slug generation for Eloquent models using traits.

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

[](#installation)

```
composer require kodooy/laravel-slug-generator
```

Database Setup
--------------

[](#database-setup)

Your Eloquent model's database table must have a `slug` field. Add it to your migration:

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

If adding to an existing table:

```
Schema::table('posts', function (Blueprint $table) {
    $table->string('slug')->unique()->index();
});
```

Usage
-----

[](#usage)

Add the `Slugable` trait to your Eloquent model:

```
use Kodooy\SlugGenerator\Traits\Slugable;

class Post extends Model
{
    use Slugable;

    // The trait will automatically generate slugs from the 'name' attribute
    // and use 'slug' as the route key
}
```

### Customization

[](#customization)

Override these methods to customize behavior:

```
class Post extends Model
{
    use Slugable;

    // Use different attribute for slug generation
    protected function slugableAttribute()
    {
        return 'title'; // default is 'name'
    }

    // Preserve existing slugs on update
    protected function preserveSlugOnUpdate()
    {
        return true; // default is false
    }
}
```

### Automatic Slug Generation

[](#automatic-slug-generation)

```
// Slug is automatically generated when creating/updating
$post = Post::create([
    'title' => 'My Blog Post',
    'content' => 'This is the content...'
]);

// Slug will be: 'my-blog-post'
echo $post->slug;
```

### Manual Slug Generation

[](#manual-slug-generation)

```
// Generate slug manually
$post = new Post(['title' => 'Another Great Post']);
$post->slug = $post->generateSlug();
```

### Unique Slug Handling

[](#unique-slug-handling)

```
// If a slug already exists, it will be made unique:
// "my-post" -> "my-post-1" -> "my-post-2" etc.

$post1 = Post::create(['title' => 'My Post']);  // slug: "my-post"
$post2 = Post::create(['title' => 'My Post']);  // slug: "my-post-1"
$post3 = Post::create(['title' => 'My Post']);  // slug: "my-post-2"
```

Requirements
------------

[](#requirements)

- PHP ^8.1
- Laravel ^9.0|^10.0|^11.0|^12.0

License
-------

[](#license)

MIT

###  Health Score

29

—

LowBetter than 60% of packages

Maintenance57

Moderate activity, may be stable

Popularity2

Limited adoption so far

Community2

Small or concentrated contributor base

Maturity46

Maturing project, gaining track record

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 ~0 days

Total

2

Last Release

285d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/1a1da6abe471f71e299fc5ad78a8603e94afde48c4a84289e524f691b235cc93?d=identicon)[kodooy](/maintainers/kodooy)

---

Tags

sluglaraveleloquenttrait

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/kodooy-laravel-slug-generator/health.svg)

```
[![Health](https://phpackages.com/badges/kodooy-laravel-slug-generator/health.svg)](https://phpackages.com/packages/kodooy-laravel-slug-generator)
```

###  Alternatives

[cviebrock/eloquent-sluggable

Easy creation of slugs for your Eloquent models in Laravel

4.0k13.6M253](/packages/cviebrock-eloquent-sluggable)[cybercog/laravel-ban

Laravel Ban simplify blocking and banning Eloquent models.

1.1k651.8k11](/packages/cybercog-laravel-ban)[cybercog/laravel-love

Make Laravel Eloquent models reactable with any type of emotions in a minutes!

1.2k302.7k1](/packages/cybercog-laravel-love)[tucker-eric/eloquentfilter

An Eloquent way to filter Eloquent Models

1.8k4.8M26](/packages/tucker-eric-eloquentfilter)[watson/validating

Eloquent model validating trait.

9723.3M47](/packages/watson-validating)[cviebrock/eloquent-taggable

Easy ability to tag your Eloquent models in Laravel.

567694.8k3](/packages/cviebrock-eloquent-taggable)

PHPackages © 2026

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