konstantinkoslow/laravel-uuid
Composer 安装命令:
composer require konstantinkoslow/laravel-uuid
包简介
UUID primary key for Laravel Eloquent Models.
README 文档
README
Trait for generating UUID primary keys for Laravel version 5.6 and higher.
Installation
Install the package via Composer:
composer require konstantinkoslow/laravel-uuid
Usage
Laravel Migrations
To let a Model make use of UUIDs as primary key, you have to add a UUID field in your migration file and set this as primary key:
Schema::create('table_name', function (Blueprint $table) { $table->uuid('id'); $table->primary('id'); // or $table->char('key', 36)->primary(); });
Eloquent will also assume that each table has a primary key column named
id. You may define a protected$primaryKeyproperty to override this convention.
For example:
<?php namespace App; use Illuminate\Database\Eloquent\Model; class ModelName extends Model { protected $primaryKey = 'key'; }
Read more Laravel - Eloquent Model Conventions.
Eloquent Model
Bind the traid with the use operator into the Model that uses UUIDs as primary key:
<?php namespace App; use Illuminate\Database\Eloquent\Model; use KonstantinKoslow\LaravelUuid\UsesUuid; class ModelName extends Model { use UsesUuid; }
License
Laravel UUID is licensed under the MIT license.
统计信息
- 总下载量: 39
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 3
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-12-08