namest/sluggable

v0.2 2015-03-05 03:07 UTC

This package is not auto-updated.

Last update: 2024-05-11 15:18:44 UTC


README

Provide an elegant way to interact with slug feature for your eloquent models.

Note: The package is only support Laravel 5

Installation

Step 1: Install package

composer require namest/sluggable

Step 2: Register service provider alias in your config/app.php

return [
    ...
    'providers' => [
        ...
        'Namest\Sluggable\SluggableServiceProvider',
    ],
    ...
];

Step 3: Publish package resources, include: configs, migrations. Open your terminal and type:

php artisan vendor:publish --provider="Namest\Sluggable\SluggableServiceProvider"

Step 4: Migrate the migration that have been published

php artisan migrate

Step 5: Use some traits to make awesome things

class User extends Model
{
    use \Namest\Sluggable\HasSlug;
    
    // ...
}

Step 6: Read API below and start happy

API

$post->slug = 'the-new-post';
$post->save(); // Save post & slug;

$slug = $post->slug; // Get slug string
Slug::isValid($name); // Check a name is valid for slug: unique & sluged
Slug::regenerate($name); // Regenerate a slug if its invalid
Slug::regenerate($name, true); // Regenerate a slug without check its valid or not

Reserve

Config slug reservation in config/slug.php file.