lucasmichot / eloquentuuid
为给定模型实例的状态提供一个独特的 Base62 编码 UUID
0.1.2
2014-06-30 12:29 UTC
Requires
- php: >=5.4.0
- illuminate/support: 4.2.*
This package is not auto-updated.
Last update: 2024-09-27 06:47:54 UTC
README
提供表示给定模型实例状态的独特 Base62 编码 UUID。
这特别有助于跟踪模型版本。
为什么使用 Base62?
与 MD5 相比,Base62 哈希更短,且使用的字母表使得处理更为简便,例如在缩短 URL 或存储在数据库中时。
要求
- PHP >= 5.4
- Laravel 4.2
包安装
首先通过 Composer 安装此包。编辑您的项目 composer.json 文件以要求 lucasmichot/eloquentuuid。
"require": { "lucasmichot/eloquentuuid": "0.*" }
然后,在终端中更新 Composer
$ composer update
您可以使用以下单行命令完成这些操作
$ composer require "lucasmichot/eloquentuuid:0.*"
用法
use Lucasmichot\Eloquentuuid\UuidTrait; class Post extends Eloquent { use UuidTrait; // the code of your model comes here }
访问 UUID
$post = Post::find(1); // update the attributes of the post echo $post->uuid();
每次修改模型时,UUID 会相应地更改。
待办事项
- 完成文档