Getting Started
Provide an elegant way to interact with slug feature for your eloquent models., (*1)
Note: The package is only support Laravel 5, (*2)
Installation
Step 1: Install package, (*3)
composer require namest/sluggable
Step 2: Register service provider alias in your config/app.php, (*4)
return [
...
'providers' => [
...
'Namest\Sluggable\SluggableServiceProvider',
],
...
];
Step 3: Publish package resources, include: configs, migrations. Open your terminal and type:, (*5)
php artisan vendor:publish --provider="Namest\Sluggable\SluggableServiceProvider"
Step 4: Migrate the migration that have been published, (*6)
php artisan migrate
Step 5: Use some traits to make awesome things, (*7)
class User extends Model
{
use \Namest\Sluggable\HasSlug;
// ...
}
Step 6: Read API below and start happy, (*8)
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., (*9)