PHPackages                             sharifuddin/laravel-smart-auto-slug - 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. sharifuddin/laravel-smart-auto-slug

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

sharifuddin/laravel-smart-auto-slug
===================================

Automatically generates clean, SEO-friendly, and unique slugs for Eloquent models with transaction-safe duplicate prevention.

1.0.0(6mo ago)02MITPHPPHP ^8.0

Since Nov 2Pushed 6mo agoCompare

[ Source](https://github.com/sharifWebDev/laravel-smart-auto-slug)[ Packagist](https://packagist.org/packages/sharifuddin/laravel-smart-auto-slug)[ Docs](https://github.com/sharifuddin/laravel-smart-auto-slug)[ RSS](/packages/sharifuddin-laravel-smart-auto-slug/feed)WikiDiscussions main Synced 1mo ago

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

Laravel Smart Auto Slug
=======================

[](#laravel-smart-auto-slug)

[![License: MIT](https://camo.githubusercontent.com/08cef40a9105b6526ca22088bc514fbfdbc9aac1ddbf8d4e6c750e3a88a44dca/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d626c75652e737667)](LICENSE.md)[![PHP Version](https://camo.githubusercontent.com/92bd3fc58c5a5c0e731827954b9d127a8ef2ce3857b22acd5c34051d294a3703/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f736861726966756464696e2f6c61726176656c2d736d6172742d6175746f2d736c7567)](https://packagist.org/packages/sharifuddin/laravel-smart-auto-slug)[![Latest Version](https://camo.githubusercontent.com/01c439d7983dd2b22615d94578c2d42e0899c29ad79a0ae7e642f473ee530128/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f736861726966756464696e2f6c61726176656c2d736d6172742d6175746f2d736c7567)](https://packagist.org/packages/sharifuddin/laravel-smart-auto-slug)[![Total Downloads](https://camo.githubusercontent.com/4e4264cc3270e36529090b8e7ef38b7a2a7c4ff43e297a18c75994acd05d69f0/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f736861726966756464696e2f6c61726176656c2d736d6172742d6175746f2d736c7567)](https://packagist.org/packages/sharifuddin/laravel-smart-auto-slug)

A professional, robust, and transaction-safe auto-slug generation package for Laravel Eloquent models. Automatically generates clean, SEO-friendly, and unique slugs with comprehensive duplicate prevention.

Features
--------

[](#features)

- 🚀 **Auto-generate SEO-friendly slugs** - Clean, readable URLs automatically
- 🔒 **Transaction-safe** - Prevents race conditions with database transactions
- 🔄 **Update-aware** - Regenerates slugs when source fields change
- 🎯 **Fully customizable** - Configure slug fields, source fields, and separators
- 🛡️ **Duplicate prevention** - Automatically handles slug conflicts
- 📦 **PSR-4 compliant** - Professional code standards
- 🧪 **Full test coverage** - Reliable and well-tested
- 🔧 **Laravel 10 &amp; 11** - Full framework support

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

[](#installation)

```
composer require sharifuddin/laravel-smart-auto-slug
---

## ⚡ Installation

Install via Composer:

```bash
composer require sharifuddin/laravel-smart-auto-slug
```

If you want, you can also publish the service provider, but the package supports **auto-discovery**.

---

🛠 Usage
-------

[](#-usage)

1. Basic Usage
--------------

[](#1-basic-usage)

```
use Illuminate\Database\Eloquent\Model;
use Sharifuddin\LaravelSmartAutoSlug\Traits\SmartAutoSlug;

class Post extends Model
{
use SmartAutoSlug;

    protected $fillable = ['title', 'content'];

}
```

### 2. Custom Configuration

[](#2-custom-configuration)

```
class Post extends Model
{
    use SmartAutoSlug;

    protected $slugField = 'url_slug'; // Default: 'slug'
    protected $slugSourceField = 'title'; // Default: 'name'

    protected $fillable = ['title', 'content', 'url_slug'];
}
```

Examples
--------

[](#examples)

```
// Creating posts with automatic slugs
$post1 = Post::create(['title' => 'My First Post']);
echo $post1->slug; // Output: "my-first-post"

$post2 = Post::create(['title' => 'My First Post']);
echo $post2->slug; // Output: "my-first-post-1"

// Slugs update when titles change
$post1->update(['title' => 'Updated Post Title']);
echo $post1->slug; // Output: "updated-post-title"
```

Manual Slug Regeneration
------------------------

[](#manual-slug-regeneration)

```
$post = Post::find(1);
$post->title = 'Completely New Title';
$post->regenerateSlug(); // Manually regenerate slug
$post->save();
```

🔧 Customization
---------------

[](#-customization)

Publish the configuration file:
-------------------------------

[](#publish-the-configuration-file)

```
php artisan vendor:publish --tag=smart-auto-slug-config
```

PropertyDefaultDescription`$slugField``slug`The database column where the slug is stored.`$slugSourceField``name`The model field used to generate the slug.The trait ensures uniqueness by checking existing slugs and appending a numeric suffix if necessary.

---

⚙️ Requirements
---------------

[](#️-requirements)

Compatibility
-------------

[](#compatibility)

Laravel VersionPHP VersionPackage Version12.x8.2+^1.011.x8.2+^1.010.x8.1+^1.09.x8.0+^1.08.x8.0+^1.0---

🧪 Testing
---------

[](#-testing)

Run the package tests using PHPUnit:

```
vendor/bin/phpunit
```

Run code analysis with PHPStan:

```
vendor/bin/phpstan analyse
```

---

📜 License
---------

[](#-license)

This package is open-sourced software licensed under the [MIT license](LICENSE).

---

👨‍💻 Author
----------

[](#‍-author)

**Sharif Uddin**

- Email:
- Website:

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance67

Regular maintenance activity

Popularity2

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity40

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

Unknown

Total

1

Last Release

191d ago

### Community

Maintainers

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

---

Top Contributors

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

---

Tags

sluglaraveleloquentlaravel-packageslug-generatorUnique Slugseo-friendlyauto-slugunique auto slugcustomizable slugseo-friendly-slug-generate

###  Code Quality

TestsPHPUnit

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/sharifuddin-laravel-smart-auto-slug/health.svg)

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

###  Alternatives

[anourvalar/eloquent-serialize

Laravel Query Builder (Eloquent) serialization

11320.2M21](/packages/anourvalar-eloquent-serialize)[salehhashemi/laravel-repository

Implementing the repository pattern for Laravel projects.

2010.5k](/packages/salehhashemi-laravel-repository)[stayallive/laravel-eloquent-observable

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

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

A package to create readable, random slugs for Eloquent models from animal names and adjectives.

226.7k](/packages/matteoggl-linnaeus)

PHPackages © 2026

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