laravelista/illaoi

该包已被废弃,不再维护。未建议替代包。

为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

为Laravel生成短链接。

支持克罗地亚字符čćžšđ。

  • 可以生成数据库的独特短链接

安装

首先,通过Composer拉取包。

"require": {
    "laravelista/illaoi": "~2.0"
}

然后,如果您使用Laravel 5.1,请将服务提供者在config/app.php中包含。

'providers' => [
    ...
    Laravelista\Illaoi\IllaoiServiceProvider::class
];

如果您愿意,可以将外观别名添加到该文件的底部

'aliases' => [
    ...
    'Illaoi' => Laravelista\Illaoi\Facades\Illaoi::class
];

API

generate($text)

只需传入一些简单文本,即可获得短链接。

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

// returns: this-is-a-post

generateUnique($text, Model $model)

当您想为模型创建唯一短链接时使用。

它在Model中通过slug查找生成的短链接,如果找到,则从数字2开始递增最后一个数字。

例如: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