PHPackages                             edofre/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. [Utility &amp; Helpers](/categories/utility)
4. /
5. edofre/laravel-sluggable

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

edofre/laravel-sluggable
========================

Generate slugs when saving Eloquent models

V1.5.2(9y ago)1215MITPHPPHP &gt;=5.6.4

Since Dec 24Pushed 9y ago1 watchersCompare

[ Source](https://github.com/Edofre/laravel-sluggable)[ Packagist](https://packagist.org/packages/edofre/laravel-sluggable)[ Docs](https://github.com/edofre/laravel-sluggable)[ RSS](/packages/edofre-laravel-sluggable/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (4)Dependencies (4)Versions (15)Used By (0)

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

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

[![Code Climate](https://camo.githubusercontent.com/6656bdf3fb92f433a9a0a51cb1758e6d704a3a3616dd79d45570fafdc7152ea6/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f45646f6672652f6c61726176656c2d736c75676761626c652f6261646765732f6770612e737667)](https://codeclimate.com/github/Edofre/laravel-sluggable)[![Latest Stable Version](https://camo.githubusercontent.com/ccfaca0504ebf379cf08a94d5b13cb823c25bf28d354dda598743901fe51c1a0/68747470733a2f2f706f7365722e707567782e6f72672f65646f6672652f6c61726176656c2d736c75676761626c652f762f737461626c65)](https://packagist.org/packages/edofre/laravel-sluggable)[![Latest Unstable Version](https://camo.githubusercontent.com/90415c26c8fd14bc5418bc9696868fe8d3f15c8c148d89165650cdb2a766d0de/68747470733a2f2f706f7365722e707567782e6f72672f65646f6672652f6c61726176656c2d736c75676761626c652f762f756e737461626c65)](https://packagist.org/packages/edofre/laravel-sluggable)[![License](https://camo.githubusercontent.com/8a6371095fa058b7437cb98a97b5140458caab2ba69b2324589dc5754ee3d0ac/68747470733a2f2f706f7365722e707567782e6f72672f65646f6672652f6c61726176656c2d736c75676761626c652f6c6963656e7365)](https://packagist.org/packages/edofre/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 '-'.

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

[](#installation)

You can install the package via composer:

```
$ composer require edofre/laravel-sluggable
```

Usage
-----

[](#usage)

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

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

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

```
