Skip to content
This repository has been archived by the owner on Feb 23, 2018. It is now read-only.

laravelista/Illaoi

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Illaoi

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