laravelista/illaoi

This package is abandoned and no longer maintained. No replacement package was suggested.

Generates slugs for Laravel.

2.0.0 2015-12-02 22:22 UTC

This package is not auto-updated.

Last update: 2022-02-01 12:53:11 UTC


README

Build Status Latest Stable Version Total Downloads Latest Unstable Version License

Generates slugs for Laravel.

Has support for croatian characters čćžšđ.

  • Can generate unique slugs for database

Installation

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
];

API

generate($text)

Just pass it some trivial text and expect slug in return.

Illaoi::generate('This is a post')

// returns: this-is-a-post

generateUnique($text, Model $model)

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

Creating new Model
Illaoi::generateUnique('This is a post', new App\Post);

// returns: this-is-a-post
Updating Model
$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