larapack/attribute-slugging
最新稳定版本:v1.0.3
Composer 安装命令:
composer require larapack/attribute-slugging
包简介
Allows your Eloquent Model to automatically generate a unique slug for a attribute on save.
README 文档
README
Allows your Eloquent Model to automatically generate a unique slug for a attribute on save.
Installing
Install using Composer composer require larapack/attribute-slugging 1.*.
Usage
First add the trait Sluggable to your Eloquent Model.
<?php
namespace App;
use Larapack\AttributeSlugging\Sluggable;
class User
{
use Sluggable;
/**
* @var array List of attribute names which should be slugged
*/
protected $slug = [
'username_slug' => 'username', // set the attribute names you which to slug and from what attribute it should be generated from
];
//...
}
Test:
// we make two user objects
$userA = new App\User;
$userB = new App\User;
// then we set both username's to "Mark"
$userA->username = "Mark";
$userB->username = "Mark";
// save both objects
$userA->save();
$userB->save();
// now the unique slugs have been set
echo $userA->username_slug; // outputs "mark"
echo $userB->username_slug; // outputs "mark-2"
统计信息
- 总下载量: 1.96k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 6
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-11-27