rap2hpoutre/has-uuid
Composer 安装命令:
composer require rap2hpoutre/has-uuid
包简介
Use both auto-increment and UUID
README 文档
README
What?
Why choose between Seq ID (aka auto-increment) and UUID when you can use both? This package helps you to add UUID to your Laravel Models.
You can also use this class if you only wants UUID without increments.
Quick start
Install with composer:
composer require rap2hpoutre/has-uuid
Add the trait to your models:
<?php class User { use \Rap2hpoutre\HasUuid\HasUuid; // ... }
Use the Trait to load your models:
$user = User::uuid('e3ae1e6b-fabb-4839-bf65-de9a892c0d56');
And when you save a model, it will magically add a UUID to it:
$user = new User; $user->name = 'raph'; $user->save(); // <- Your user has now a UUID (and a ID if you have not removed it)
PS: don't forget to add the UUID in your migrations:
<?php class CreateSesNotificationsTable extends \Illuminate\Database\Migrations\Migration { public function up() { \Schema::create('user', function ($table) { $table->increments('id'); $table->uuid('uuid')->index(); // <- THIS. $table->string('email')->index(); $table->timestamps(); }); } // ... }
统计信息
- 总下载量: 354
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-10-04