jamesh/laravel-uuid

该包已被废弃,不再维护。作者建议使用 Laravel 9+ 提供的 HasUuids trait 包代替。

Laravel 6及更高版本的 Eloquent UUID 特性。

安装次数: 59,652

依赖: 0

建议者: 0

安全: 0

星标: 21

关注者: 1

分支: 8

开放问题: 0

类型:插件

2.0.1 2022-02-26 21:49 UTC

This package is auto-updated.

Last update: 2022-11-11 20:22:40 UTC


README

Laravel 5.7及更高版本的 Eloquent UUID 特性。

⚠️ 此包将不再维护。 Laravel 9 已添加 HasUuids 功能。

Github Actions Total Downloads MIT licensed

HasUuid 特性将为创建和保存 Eloquent 事件添加生成 Uuid 的行为。

安装

composer require jamesh/laravel-uuid

使用

在你的迁移中

Schema::create('users', function (Blueprint $table) {
    $table->uuid('id')->primary(); // Create CHAR(36)
    $table->string('name');
    $table->string('email')->unique();
    $table->timestamp('email_verified_at')->nullable();
    $table->string('password');
    $table->rememberToken();
    $table->timestamps();
});

在你的模型中

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use Jamesh\Uuid\HasUuid;

class User extends Model
{
    use HasUuid;
}

单元测试

要运行测试,只需运行 composer installcomposer test