在Laravel中我們使用composer進(jìn)行安裝 vinkla/hashids開源庫,可以將字符串ID轉(zhuǎn)化為數(shù)字ID。
我們使用composer進(jìn)行安裝,最新的laravel-hashids 需要Laravel 5.6版本以上支持。
$ composer require vinkla/hashids
擴(kuò)展包配置
$ php artisan vendor:publish
GitHUB項(xiàng)目地址:https://github.com/vinkla/laravel-hashids
使用示例代碼:
使用use引入Hashids
// You can alias this in config/app.php.
use Vinkla\Hashids\Facades\Hashids;
對字符串進(jìn)行加密
Hashids::encode(4815162342);
// We're done here - how easy was that, it just works!
對字符串進(jìn)行解密
Hashids::decode('doyouthinkthatsairyourebreathingnow');
// This example is simple and there are far more methods available.
我們使用composer進(jìn)行安裝,最新的laravel-hashids 需要Laravel 5.6版本以上支持。
$ composer require vinkla/hashids
擴(kuò)展包配置
$ php artisan vendor:publish
GitHUB項(xiàng)目地址:https://github.com/vinkla/laravel-hashids
使用示例代碼:
使用use引入Hashids
// You can alias this in config/app.php.
use Vinkla\Hashids\Facades\Hashids;
對字符串進(jìn)行加密
Hashids::encode(4815162342);
// We're done here - how easy was that, it just works!
對字符串進(jìn)行解密
Hashids::decode('doyouthinkthatsairyourebreathingnow');
// This example is simple and there are far more methods available.