kblais/laravel-uuid
最新稳定版本:v2.3.0
Composer 安装命令:
composer require kblais/laravel-uuid
包简介
A simple library to use UUIDs as your Eloquent model's primary key.
README 文档
README
A simple library to use UUIDs as your Eloquent model's primary key.
Why should I use UUIDs ?
To answer this question, I simply recommend you read this blog post.
OK, I'm convinced now. How do I install this ?
Require this package with Composer :
composer require kblais/laravel-uuid - the package internally use ramsey/uuid to generate the UUIDs.
Usage
First, your model's column must be a 36 characters column :
- Laravel v4
$table->char('id', 36); $table->primary('id');
- Laravel v5+
$table->uuid('id'); $table->primary('id');
Then, just add the Kblais\Uuid\Uuid trait to your model, and you're done :
<?php namespace App; use Illuminate\Database\Eloquent\Model; use Kblais\Uuid\Uuid; class User extends Model { use Uuid; }
Version 4 UUIDs are used by default. You can change this by overriding the $uuidVersion & $uuidString variables. For example :
protected $uuidVersion = 1; protected $uuidString = ''; // only needed when $uuidVersion is "3 or 5"
The supported UUIDs versions here are "1, 3, 4 and 5".
统计信息
- 总下载量: 80.11k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 10
- 点击次数: 4
- 依赖项目数: 3
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-01-04