paulhenri-l/laravel-has-uuid

1.0.1 2021-09-22 22:00 UTC

This package is auto-updated.

Last update: 2024-09-23 04:51:48 UTC


README

Tests License: MIT

轻松将uuid用作您Eloquent模型的唯一键。

安装

composer require paulhenri-l/laravel-has-uuid

使用方法

此功能作为特质提供,您应该在模型中使用它。

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Hello extends Model
{
    use \PaulhenriL\LaravelHasUuid\HasUuid;
}

您还应在迁移中使用uuid字段而不是默认的id字段。

Schema::create('hellos', function (Blueprint $table) {
    $table->uuid('id')->primary();
    $table->timestamps();
});

现在,每当您创建一个新模型时,它将获得一个uuid而不是递增的id。