Lumen/laravel使用UUID

安装Uuid

1
composer require webpatser/laravel-uuid

配置全局函数使用 UUID

  • 配置全局函数得方法参照另外一篇 《添加全局自定义函数》
  • 在全局函数文件中添加如下代码
1
2
3
4
5
6
7
8
use Webpatser\Uuid\Uuid;
/**
* 生成 uuid "de99ff30-6d4c-11e8-b243-27600b662ccc"
* @return string
*/
function uuid() {
return Uuid::generate()->string;
}