Skip to content
Shipu Ahamed edited this page Sep 3, 2016 · 1 revision

Configuration

Configuration was designed to be as flexible as possible. You can set up defaults for all of your Eloquent models, and then override those settings for individual models.

By default, global configuration can be set in the app/config/sluggable.php file. If a configuration isn't set, then the package defaults from vendor/cviebrock/eloquent-sluggable/resources/config/sluggable.php are used. Here is an example configuration, with all the default settings shown:

return [
    'source'          => null,
    'maxLength'       => null,
    'method'          => null,
    'separator'       => '-',
    'unique'          => true,
    'uniqueSuffix'    => null,
    'includeTrashed'  => false,
    'reserved'        => null,
];

For individual models, configuration is handled in the sluggable() method that you need to implement. That method should return an indexed array where the keys represent the fields where the slug value is stored and the values are the configuration for that field.

public function sluggable()
{
    return [
        'title-slug' => [
            'source' => 'title'
        ],
        'author-slug' => [
            'source' => ['author.firstname', 'author.lastname']
        ],
    ];
}

Unlike previous versions of the package, this now means you can now create multiple slugs for the same model, based on different source strings and with different configuration options. For example:

public function sluggable()
{
    return [
        'title-slug' => [
            'source' => 'title'
        ],
        'author-slug' => [
            'source' => ['author.firstname', 'author.lastname'],
            'separator' => '_'
        ],
    ];
}
Clone this wiki locally