alexanderzon / laravel-hashids
从toran/hashids分支:Laravel包用于Hashids
3.0.1
2015-04-09 07:34 UTC
Requires
- php: >=5.3.0
- alexanderzon/hashids: 1.0.*@dev
This package is not auto-updated.
Last update: 2024-09-28 17:43:44 UTC
README
本包使用了hashids.org创建的类
从数字生成散列,例如YouTube或Bitly。当您不希望将数据库ID暴露给用户时使用hashids。
安装
要获取Hashids的最新版本,只需在您的composer.json
文件中添加它。
"alexanderzon/laravel-hashids": "dev-master"
然后您需要运行composer install
来下载它并更新自动加载器。
一旦安装了Hashids,您需要将服务提供者注册到应用程序中。打开config/app.php
并找到providers
键。
'AlexanderZon\Hashids\HashidsServiceProvider'
不需要添加外观,包会为您添加。
发布配置
从项目根目录在命令行上运行此操作
$ php artisan config:publish alexanderzon/laravel-hashids
将配置文件发布到config/laravel-hashids.php
。
Laravel 4安装
在您的composer.json
文件中添加Hashids的1.0版本。
"alexanderzon/laravel-hashids": "3.0.*"
并按照README中1.0版本的说明。
使用方法
完成所有步骤并完成安装后,您可以使用Hashids。
编码
您可以简单地编码一个ID
Hashids::encode(1); // Returns Ri7Bi
或多个...
Hashids::encode(1, 21, 12, 12, 666); // Returns MMtaUpSGhdA
解码
Hashids::decode(Ri7Bi); // Returns int 1
或多个...
Hashids::decode(MMtaUpSGhdA); // Returns array (size=5) 0 => int 1 1 => int 21 2 => int 12 3 => int 12 4 => int 666
变更日志
2.0.0
- 升级到Laravel 5
- 升级到Hashids 1.0.5
1.0.0
-
几个公共函数被重命名,以更合适
- 函数
encrypt()
更改为encode()
- 函数
decrypt()
更改为decode()
- 函数
encryptHex()
更改为encodeHex()
- 函数
decryptHex()
更改为decodeHex()
Hashids被设计用于编码整数,最多为主键。Hashids不是加密敏感数据的正确算法。因此,为了鼓励更合适的使用,
encrypt/decrypt
正在被“降级”为encode/decode
。 - 函数
-
添加了版本标签:
1.0
-
README.md
已更新
所有关于Hashids的荣誉都归功于Ivan Akimov (@ivanakimov),感谢他为它做出贡献!