rollswan / uuid
生成作为主键的全局唯一标识符
1.0.0
2020-10-20 05:28 UTC
This package is auto-updated.
Last update: 2024-09-05 00:34:02 UTC
README
一个用于生成主键uuid的Laravel包。
如何使用?
- 安装
composer require rollswan/uuid
- 在迁移中使用
uuid()
示例
Schema::create('posts', function (Blueprint $table) {
$table->uuid(); // you can also custom your uuid `uuid('post_uuid')`
$table->string('title');
$table->string('body');
$table->timestamps();
});
- 在您的模型中使用
WithUuid
特性并声明主键
示例
namespace App;
use Rollswan\Uuid\Traits\WithUuid;
use Illuminate\Database\Eloquent\Model;
class Post extends Model
{
use WithUuid;
protected $primaryKey = 'uuid';
}
完成!这将在您保存新记录时自动生成唯一的UUID。