Laravel 审计和 UUIDS?

Laravel Audit and UUIDS?

我正在使用 laravel 审计它显示 UUID 错误我认为,我已经安装并配置 http://www.laravel-auditing.com/docs/9.0/installation 的 laravel 审计并更改 user_id 和id 到默认类型为 bigInteger

的 UUID
  public function up()
{
    Schema::create('audits', function (Blueprint $table) {
        $table->uuid('id')->primary();
        $table->string('user_type')->nullable();
        $table->uuid('user_id')->nullable();
        $table->string('event');
        $table->morphs('auditable');
        $table->text('old_values')->nullable();
        $table->text('new_values')->nullable();
        $table->text('url')->nullable();
        $table->ipAddress('ip_address')->nullable();
        $table->string('user_agent', 1023)->nullable();
        $table->string('tags')->nullable();
        $table->timestamps();
        
    });
}

我也在 audit.php 中使用了 UUID 特征,就像我在其他项目模型中所做的那样 我迁移了它创建的项目 table 当我存储数据时它显示以下错误

SQLSTATE[22P02]: Invalid text representation: 7 ERROR: invalid input syntax for type bigint: "974afba9-556e-4ecd-bd42-aaf12ce9aab0" (SQL: insert into "audits" ("old_values", "new_values", "event", "auditable_id", "auditable_type", "user_id", "user_type", "url", "ip_address", "user_agent", "tags", "id", "updated_at", "created_at") values ([], {"title":"Magnam nulla perfere","code":"Temporibus in ut cul","created_by":"2d03731c-9c71-4238-bdfc-03e3f556ddef","end_date":"2012-09-29","start_date":"2016-12-02","currency":"PKR","status":"Ongoing","budget":"32","objectives":"Architecto adipisci","specificobjectives":"Eveniet harum repre","abreviation":"Aut iusto quod quia","pcr_deadline":"1976-04-28","donor":"UNICEF","donor_fp_name":"Tanner Noble","donor_fp_email":"gyvimyz@mailinator.com","donor_fp_designation":"Ut vel quidem sed fa","donor_fp_mobile":"Qui sit provident","donor_fp_phone_office":"+1 (832) 163-8003","brsp_fp_email":"wygihihyw@mailinator.com","brsp_fp_name":"Myles Cameron","brsp_fp_designation":"Laboris ut eius ut e","brsp_fp_mobile":"Doloribus quis possi","brsp_fp_phone_office":"+1 (891) 256-8645","reporting_frequency":"Monthly","id":"974afba9-556e-4ecd-bd42-aaf12ce9aab0","updated_at":"2021-07-13 15:32:09","created_at":"2021-07-13 15:32:09"}, created, 974afba9-556e-4ecd-bd42-aaf12ce9aab0, App\Models\Project, 2d03731c-9c71-4238-bdfc-03e3f556ddef, App\Models\User, http://localhost:8000/project/store, 127.0.0.1, Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36, ?, eda36c0b-13c3-42c1-a345-fe2bb4b27520, 2021-07-13 15:32:09, 2021-07-13 15:32:09))

documentation 声明当在模型中使用 UUID 而不是自动递增 ID 时,您必须在 audits table 迁移中进行以下更改。

UUID over auto-incrementing ids

Some developers prefer to use a UUID instead of auto-incrementing ids. If that's the case, make sure to update the up() method like so:

For the User, change from

$table->nullableMorphs('user');

to

$table->uuid('user_id')->nullable();
$table->string('user_type')->nullable();
$table->index([
    'user_id', 
    'user_type',
]);

For the Auditable model, change from

$table->morphs('auditable');

to

$table->uuid('auditable_id');
$table->string('auditable_type');
$table->index([
   'auditable_id', 
   'auditable_type',
]);

您已经更改了 User 变形,但您忘记了 Auditable 变形。