marcohern / slugifier
此包的最新版本(1.0.2)没有提供许可信息。
简化你的生活
1.0.2
2019-08-24 16:43 UTC
Requires (Dev)
- phpunit/phpunit: ^8
This package is auto-updated.
Last update: 2024-09-25 08:06:30 UTC
README
Laravel的slug管理。 marcohern/slugifier 并非另一个slug生成器(这类工具已经很多),它通过记录slug的唯一性来管理slug,并使用索引记录重复的slug。
安装
使用composer安装
$ composer require marcohern/slugifier
运行迁移以包含slugifier表。
$ php artisan migrate
使用Slugifier管理库。
use Marcohern\Slugifier\Lib\Slugifier;
构建slugifier。
$slugifier = new Slugifier();
你现在可以开始使用slugifier方法了。
slugify
通过调用Laravel的标准 str_slug 辅助函数来实现slugify。
echo $slugifier->slugify('Death Stranding'); //output: death-stranding
check
将源转换为slug并验证其在数据库中的状态:是否正在使用以及其序列。
$result = $slugifier->check('Death Stranding','Games'); /* $result == [ 'entity' => 'games', 'slug' => 'death-stranding', 'sequence' => 0 ] */
store
与check相同,但它还会将序列增加1。多次调用它会导致序列每次增加。
$result = $slugifier->store('Death Stranding','Games'); /* first time $result == [ 'entity' => 'games', 'slug' => 'death-stranding', 'sequence' => 0 ] */ $result = $slugifier->store('Death Stranding','Games'); /* second time $result == [ 'entity' => 'games', 'slug' => 'death-stranding-1', 'sequence' => 1 ] */