recycledbeans / eloquent-uuid
快速简单地在Laravel Eloquent模型中使用UUID主键。
v1.0.0
2020-08-12 23:21 UTC
README
快速简单地在Laravel Eloquent模型中使用UUID主键。
安装
只需使用composer添加包到您的Laravel应用中。
composer require recycledbeans/eloquent-uuid
用法
确保您的迁移使用uuid()
字段类型,并将该字段设置为主键。
Schema::create('documents', function (Blueprint $table) { $table->uuid('id')->primary(); $table->timestamps(); });
然后,在您的Eloquent模型中使用UUID
特质,以确保模型自动使用UUID主键。
<?php namespace App; use Illuminate\Database\Eloquent\Model; use RecycledBeans\EloquentUUID\UUID; class Document extends Model { use UUID; }