fahriztx/model-uuid

一个用于处理UUID作为主键的Laravel包

安装: 1

依赖项: 0

建议者: 0

安全性: 0

星级: 0

关注者: 1

分支: 0

开放问题: 0

类型:laravel-package

v1.0.0 2024-07-23 14:59 UTC

This package is auto-updated.

Last update: 2024-09-23 15:25:47 UTC


README

一个用于处理UUID作为主键的Laravel包

要求

  • Laravel 10.x

简单安装

在您的Laravel项目中运行以下命令

composer require fahriztx/model-uuid

确保您的迁移文件有一个类型为UUID(使用 $table->uuid)的列作为主键。

示例

    public function up(): void
    {
        Schema::create('your_migration', function (Blueprint $table) {
            $table->uuid('id')->primary();  // Primary Key using $table->uuid('your_primary_column')->primary();
            ...
            $table->timestamps();
        });
    }

用法

use \Fahriztx\ModelUuid\Uuid; 添加到您的模型中。

示例 Models/YourModel.php

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class YourModel extends Model
{
    use HasFactory;
    use \Fahriztx\ModelUuid\Uuid; // <-- Insert this line on top of your model
}