在Laravel中我们使用composer进行安装 vinkla/hashids开源库,可以将字符串ID转化为数字ID。
我们使用composer进行安装,最新的laravel-hashids 需要Laravel 5.6版本以上支持。
$ composer require vinkla/hashids
扩展包配置
$ php artisan vendor:publish
GitHUB项目地址:https://github.com/vinkla/laravel-hashids
使用示例代码:
使用use引入Hashids
// You can alias this in config/app.php.
use Vinkla\Hashids\Facades\Hashids;
对字符串进行加密
Hashids::encode(4815162342);
// We're done here - how easy was that, it just works!
对字符串进行解密
Hashids::decode('doyouthinkthatsairyourebreathingnow');
// This example is simple and there are far more methods available.
我们使用composer进行安装,最新的laravel-hashids 需要Laravel 5.6版本以上支持。
$ composer require vinkla/hashids
扩展包配置
$ php artisan vendor:publish
GitHUB项目地址:https://github.com/vinkla/laravel-hashids
使用示例代码:
使用use引入Hashids
// You can alias this in config/app.php.
use Vinkla\Hashids\Facades\Hashids;
对字符串进行加密
Hashids::encode(4815162342);
// We're done here - how easy was that, it just works!
对字符串进行解密
Hashids::decode('doyouthinkthatsairyourebreathingnow');
// This example is simple and there are far more methods available.