PHPackages                             fomvasss/laravel-slugmaker - 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. fomvasss/laravel-slugmaker

AbandonedArchivedLibrary

fomvasss/laravel-slugmaker
==========================

Generate slugs when saving Eloquent models in a separate table

1.1.2(8y ago)1331[1 issues](https://github.com/fomvasss/laravel-slugmaker/issues)MITPHPPHP &gt;=7.0.0

Since Jan 11Pushed 8y ago1 watchersCompare

[ Source](https://github.com/fomvasss/laravel-slugmaker)[ Packagist](https://packagist.org/packages/fomvasss/laravel-slugmaker)[ Docs](https://github.com/fomvasss/laravel-slugmaker)[ RSS](/packages/fomvasss-laravel-slugmaker/feed)WikiDiscussions master Synced today

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

Generate slugs in a separate table when saving Eloquent models
==============================================================

[](#generate-slugs-in-a-separate-table-when-saving-eloquent-models)

[![Latest Version on Packagist](https://camo.githubusercontent.com/1029a1cb0f9d23827823065a21690dca40cbdd5daead2ac977b4e19c3a54ee94/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f666f6d76617373732f6c61726176656c2d736c75676d616b65722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/fomvasss/laravel-slugmaker)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Quality Score](https://camo.githubusercontent.com/0a4955062f9c4019dee0f0459c876b295658ebb047f442e1ceebbc23458a7a04/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f666f6d76617373732f6c61726176656c2d736c75676d616b65722e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/fomvasss/laravel-slugmaker)[![StyleCI](https://camo.githubusercontent.com/2790ebc32e45fddcd4602d870328d162de3a816cb5748e4ed37481f3cce32838/68747470733a2f2f7374796c6563692e696f2f7265706f732f3131323836373234302f736869656c643f6272616e63683d6d6173746572)](https://styleci.io/repos/112867240)[![Total Downloads](https://camo.githubusercontent.com/05fbf0499631e0828f640cb8ef88c73e8285e976b32ba6432ac8582ee9ca64a8/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f666f6d76617373732f6c61726176656c2d736c75676d616b65722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/fomvasss/laravel-slugmaker)

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

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 fomvasss/laravel-slugmaker
```

---

! For Laravel &lt; v5.5

Add the ServiceProvider to the providers array in config/app.php:

```
Fomvasss\SlugMaker\SlugMakerServiceProvider::class,
```

---

Publish config file:

```
php artisan vendor:publish --tag=slugmaker-config
```

Publish the migration file:

```
php artisan vendor:publish --tag=slugmaker-migrations
```

and run the migration:

```
php artisan migrate
```

Usage
-----

[](#usage)

### Configure

[](#configure)

! Pay attention! Your model should not have a field named "slug"

Your Eloquent models should use the `Fomvasss\SlugMaker\ModelHasSlug` trait.

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

Also the trait contains public method `slug()` for relations your item-model with item-slug:

```
public function slug()
{
    return $this->morphOne(\Fomvasss\SlugMaker\Models\Slug::class, 'slugable');
}
```

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

```
