bmatovu/laravel-eloquent-uuid

该包已被弃用,不再维护。未建议替代包。

Laravel Eloquent UUID。

v1.1.0 2021-03-20 19:08 UTC

This package is auto-updated.

Last update: 2023-03-01 06:54:04 UTC


README

该包已不再维护...

Laravel 从 V9 版本开始已在核心中引入了 UUID & ULID 支持

https://laravel.net.cn/docs/9.x/eloquent#uuid-and-ulid-keys

Laravel Eloquent UUID。

Build Status Scrutinizer Code Quality Code Coverage StyleCI Documentation

安装

通过 Composer 包管理器安装

composer require bmatovu/laravel-eloquent-uuid

使用方法

迁移:

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateClientsTable extends Migration
{
    public function up()
    {
        Schema::create('clients', function (Blueprint $table) {
            $table->uuid('id');
            $table->string('name');
            // ...
            $table->timestamps();

            $table->primary('id');
        });
    }
}

模型:

use Bmatovu\Uuid\Traits\HasUuidKey;
use Illuminate\Database\Eloquent\Model;

class Client extends Model
{
    use HasUuidKey;
    
    /**
     * The "type" of the primary key ID.
     *
     * @var string
     */
    protected $keyType = 'string';

    /**
     * Indicates if the IDs are auto-incrementing.
     *
     * @var bool
     */
    public $incrementing = false;
}

测试

事件伪造后工厂失败: (问题 #19952)

调用 Event::fake() 后,将不会执行任何事件监听器。因此,如果您的测试使用使用 HasUuidKey 特性的模型工厂;您应该在使用工厂后调用 Event::fake()。