haymetg / luuid
一个用于创建UUID主键的Laravel包
1.0.1
2020-06-30 00:34 UTC
This package is auto-updated.
Last update: 2024-09-29 05:36:24 UTC
README
一个用于创建uuid主键的Laravel包。
如何使用?
- 安装
composer require haymetg/luuid
- 在迁移中使用
luuid()
示例
Schema::create('posts', function (Blueprint $table) {
$table->luuid(); // you can also custom your luuid `luuid('post_id')`
$table->string('title');
$table->string('body');
$table->timestamps();
});
- 在你的Model中使用
WithUuid
特性并声明主键
示例
namespace App;
use HaymeTG\LUUID\Traits\WithUuid;
use Illuminate\Database\Eloquent\Model;
class Post extends Model
{
use WithUuid;
protected $primaryKey = 'uuid';
}
完成!每次保存新记录时,它将自动生成唯一的UUID。
致谢
Liam-senpai https://github.com/liamdemafelix