Generates slugs for Laravel.
Has support for croatian characters čćžšđ.
- Can generate unique slugs for database
First, pull in the package through Composer.
"require": {
"laravelista/illaoi": "~2.0"
}
And then, if using Laravel 5.1, include the service provider within config/app.php
.
'providers' => [
...
Laravelista\Illaoi\IllaoiServiceProvider::class
];
And if you want you can add a facade alias to this same file at the bottom:
'aliases' => [
...
'Illaoi' => Laravelista\Illaoi\Facades\Illaoi::class
];
Just pass it some trivial text and expect slug in return.
Illaoi::generate('This is a post')
// returns: this-is-a-post
Use this when you want to create a unique slug for a model.
It searches for generated slug in Model by slug
and if found increments last number by 1 starting from number 2.
eg. this-is-a-post, this-is-a-post-2, this-is-a-post-3
Illaoi::generateUnique('This is a post', new App\Post);
// returns: this-is-a-post
$post = App\Post::create([
'id' => 1,
'title' => 'This is a post,
'seo_slug' => 'this-is-a-post'
]);
Illaoi::searchBy('seo_slug')
->ignoreId(1)
->generateUnique('This is a post', new App\Post);
// returns: this-is-a-post
Illaoi::generateUnique('This is a post', new App\Post);
// returns: this-is-a-post-2
Illaoi::setIteration(1)->generateUnique('This is a post', new App\Post);
// returns: this-is-a-post-1