PHPackages                             caturseptian/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. caturseptian/laravel-sluggable

ActiveLibrary

caturseptian/laravel-sluggable
==============================

Generate slugs when saving Eloquent models

07PHP

Since Mar 10Pushed 6y ago1 watchersCompare

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

READMEChangelogDependenciesVersions (1)Used By (0)

Generate slugs when saving Eloquent models
==========================================

[](#generate-slugs-when-saving-eloquent-models)

[![Latest Version on Packagist](https://camo.githubusercontent.com/04e459a472439650ccfa5aaee0b9a05ceaaa02140ce809f4cda60c1ca188d7f8/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7370617469652f6c61726176656c2d736c75676761626c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/spatie/laravel-sluggable)[![MIT Licensed](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![GitHub Workflow Status](https://camo.githubusercontent.com/302831f7d0d791415d9de6cafde407fb3e4fabb6671e44d71fb30a4bc619f12c/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f7370617469652f6c61726176656c2d736c75676761626c652f72756e2d74657374733f6c6162656c3d7465737473)](https://camo.githubusercontent.com/302831f7d0d791415d9de6cafde407fb3e4fabb6671e44d71fb30a4bc619f12c/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f7370617469652f6c61726176656c2d736c75676761626c652f72756e2d74657374733f6c6162656c3d7465737473)[![Quality Score](https://camo.githubusercontent.com/e39060cd9ee10283b6c95618f8895d96c50d08bf0d5a3270adb6025450e6a216/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f7370617469652f6c61726176656c2d736c75676761626c652e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/spatie/laravel-sluggable)[![StyleCI](https://camo.githubusercontent.com/63cf9ea39b289cd4bcdabffa5e546d9316202cfc44dc712b3cb8988b3414b7a5/68747470733a2f2f7374796c6563692e696f2f7265706f732f34383531323536312f736869656c643f6272616e63683d6d6173746572)](https://styleci.io/repos/48512561)[![Total Downloads](https://camo.githubusercontent.com/a6ebf5dcacdaed45b2a78019c976252e12f761adeb23d0ab8c2fccfe2d2673a5/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7370617469652f6c61726176656c2d736c75676761626c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/spatie/laravel-sluggable)

This package provides a trait that will generate a unique slug when saving any Eloquent model.

```
$model = new EloquentModel();
$model->name = 'activerecord is awesome';
$model->save();

echo $model->slug; // ouputs "activerecord-is-awesome"
```

The slugs are generated with Laravels `Str::slug` method, whereby spaces are converted to '-'.

Spatie is a webdesign agency based in Antwerp, Belgium. You'll find an overview of all our open source projects [on our website](https://spatie.be/opensource).

Support us
----------

[](#support-us)

We invest a lot of resources into creating [best in class open source packages](https://spatie.be/open-source). You can support us by [buying one of our paid products](https://spatie.be/open-source/support-us).

We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on [our contact page](https://spatie.be/about-us). We publish all received postcards on [our virtual postcard wall](https://spatie.be/open-source/postcards).

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

[](#installation)

You can install the package via composer:

```
composer require caturseptian/laravel-sluggable
```

Usage
-----

[](#usage)

Your Eloquent models should use the `Spatie\Sluggable\HasSlug` trait and the `Spatie\Sluggable\SlugOptions` class.

The trait contains an abstract method `getSlugOptions()` that you must implement yourself.

Your models' migrations should have a field to save the generated slug to.

Here's an example of how to implement the trait:

```
