larastuffs/primary-uuid

在Laravel模型中使用UUID作为主键

v0.3 2021-05-17 17:47 UTC

This package is auto-updated.

Last update: 2024-09-18 01:16:19 UTC


README

Packagist Version License

此包提供了一个简单接口,用于在模型中使用UUID作为主键

要求

  • PHP 7.2或更高版本
  • Laravel 6.* | 7.* | 8.*

安装

使用以下命令使用composer安装此包

composer require larastuffs/primary-uuid

使用方法

按照说明调整您的模型和迁移

模型设置

<?php
use ...;
use LaraStuffs\PrimaryUUID\Eloquent\Concerns\UseUUIDAsPrimaryKey;

class MyModel extends Model {
 
    use UseUUIDAsPrimaryKey;
 
    ...
}

迁移设置

<?php
Schema::create('table_name', function (Blueprint $table) {
    $table->uuid('id')->primary();
});

可能的不兼容性

如果您使用闭包来定义模型事件,我强烈建议您使用模型观察者

贡献

欢迎贡献。Fork,改进并提交pull请求。对于错误,改进想法或其他,请创建一个问题