DEV Community

Muhamad Jamil
Muhamad Jamil

Posted on

2 2

generate unique slug with eloquent-sluggable package laravel 8

First install the package with composer composer require cviebrock/eloquent-sluggable

and simply put this code in your model

use Cviebrock\EloquentSluggable\Sluggable;

class Post extends Model
{
    use Sluggable;
    public function sluggable(): array
    {
        return [
            'slug' => [
                'source' => 'title'
            ]
        ];
    }
}
Enter fullscreen mode Exit fullscreen mode

it will automatically use title as a slug

for more feature, maybe you want to read the documentations

thanks for reading, if you have a better method, feel free to discuss

Top comments (0)

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more