kdaws-com / laravel-uuid
Laravel 的 Eloquent UUID 特性
1.0.0
2021-09-20 13:37 UTC
Requires
- php: ^8.0
- illuminate/database: ^8
- illuminate/support: ^8
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.1
- orchestra/testbench: ^6
- pestphp/pest: ^1.18
- pestphp/pest-plugin-laravel: ^1.1
README
一对 Eloquent 模型特性,用于处理可排序的 UUID 主键或次键。
用法
主键
模型
Use \KDAWScom\LaravelUuid\HasUuidPrimary;
class MyModel extends Model
{
Use HasUuidPrimary;
}
迁移
return new class extends Migration
{
public function up()
{
Schema::create('my_models', function (Blueprint $table) {
$table->string('id', 36)->primary();
// OR
$table->string('myKeyNameWillBeAutoDiscovered', 36)->primary();
}
}
}
次键
模型
Use \KDAWScom\LaravelUuid\HasUuidSecondarys;
class MyModel extends Model
{
Use HasUuidSecondary;
}
迁移
return new class extends Migration
{
public function up()
{
Schema::create('my_models', function (Blueprint $table) {
/**
* Default key name is uuid
*/
$table->string('uuid', 36);
/**
* You can also set your own key name, but you must remember to set the value of:
*
* $laravelUuidSecondaryKeyName
*
* to the key name inside your models boot routine
*/
$table->string('myUuidKey', 36);
}
}
}