Simplest Sluggable for Laravel Eloquent/Model to convert string into a slug.

Moamen Eltouny (Raggi)
PHP Version : >= 7.2 Laravel Version : >= 6.0 License Support
Source Packagist Version Packagist Downloads


Sluggable requires the Multibyte String mbstring extension from PHP.

Install the latest version using Composer

composer require pharaonic/laravel-sluggable

Create a slug column on the table

Just add this line to your Migration file.


Sluggable with the model

Include Sluggable into the model.

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Pharaonic\Laravel\Sluggable\Sluggable;

class Article extends Model
    use Sluggable;

    * Sluggable attribute's name
    * @var string
    protected $sluggable = 'title';

    * The attributes that are mass assignable.
    * @var array
    protected $fillable = ['title', ...];

How To Use

Simply create/update your object.

$article = Article::create(['title' => 'Moamen Eltouny']);
echo $article->slug;

Blade Directive

Generate Slug from String.

@slug('Moamen Eltouny')

Config Manipulation

Getting config file into your project.

php artisan vendor:publish --tag="laravel-sluggable"

You can find your config file in that path /config/Pharaonic/sluggable.php .

return [
    // Keep the slug Unique
    'unique'    => true,

    // Generate slug on Eloquent Create
    'onCreate'  => true,

    // Generate slug on Eloquent Update
    'onUpdate'  => true