ddlabs/uuid-package
最新稳定版本:2
Composer 安装命令:
composer require ddlabs/uuid-package
包简介
Package to allow you to use UUID for primary key in Laravel Models
README 文档
README
DiegoLabs UUID Package
Simple package to allow you to add UUID to Laravel Models via a trait.
Install
composer require ddlabs/uuid-package
Traits
- SetsUuidWhenCreating - This sets the primary key of the model to a UUID. It allows you to pass a UUID if you have a workflow that creates a UUID by default. If the UUID is version 4 compliant, then the trait will just us the UUID passed to it. We use this from time to time when records are created on a mobile device then passed to a backend via an API. They may already have a UUID associated with it.
Usage
ID must be configured in the database to accept a UUID.
For Migrations:
public function up()
{
Schema::create('your_models', function (Blueprint $table) {
$table->uuid('id'); // Set to uuid
$table->string('name');
$table->timestamps();
$table->primary('id'); // Add primary key
});
}
For Models:
use Ddlabs\Uuid\Traits\SetsUuidWhenCreating;
class YourModel extends Model
{
use SetsUuidWhenCreating;
public $incrementing = false;
protected $keyType = 'string';
...
}
统计信息
- 总下载量: 6.7k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-03-02