rvzug/laravel-possible-composite-key

PHP trait 用于在 Laravel Eloquent 模型中使用组合键,并在可能缺少列的情况下不会失败。

1.0.1 2017-09-18 22:47 UTC

This package is not auto-updated.

Last update: 2024-09-29 02:59:01 UTC


README

PHP trait 用于在 Laravel Eloquent 模型中使用组合键,并在可能缺少列的情况下不会失败。

安装

composer require rvzug/laravel-possible-composite-key

用法

<?php

use Rvzug\CanHasCompositeKey;
use Illuminate\Database\Eloquent\Model;

class MyModel extend Model {
    use CanHasCompositeKey;
    
    protected $primaryKey = ['one', 'two', 'three'];
    public $incrementing = false;
    
}

在你的迁移/数据库中,现在可以添加 'one', 'two', 'three' 的 Nullable。假设其他至少有一个被填充了近似唯一的值。例如 ArticleCode 或 Gtin 值。在我的使用中,我使用键 'ArticleCode', 'EanCode', 'Supplier',其中代码和 ean 可以为空。供应商和一个代码的组合是相对唯一的。