notpurpell/composito

Composito 是一个小型包,它通过特性赋予 eloquent 模型拥有复合主键的能力。

1.0.0 2020-03-07 11:00 UTC

This package is auto-updated.

Last update: 2024-09-07 22:08:42 UTC


README

Composito 是一个小型包,它通过特性赋予 eloquent 模型拥有复合主键的能力。

安装

您可以使用 Composer 安装 composito

composer require notpurpell/composito

用法

要将复合主键功能添加到您的 eloquent 模型中,您必须

  1. 使用 HasCompositePrimaryKey 特性。
  2. 使用 $primaryKey 属性指定复合主键。
  3. $incrementing 属性设置为 false。
use Composito\Traits\HasCompositePrimaryKey;

class MyModel extends Eloquent
{
    use HasCompositePrimaryKey;
    
    /**
     * Indicates if the IDs are auto-incrementing.
     * @var bool
     */
    public $incrementing = false;

    /**
     * The composite primary key of the model.
     * @var array
     */
    protected $primaryKey = [ "primary_one", "primary_two" ];

    ...
}

然后,您可以使用 create()save()update()delete() 方法进行常规操作。

find() 等其他方法的支持即将推出。

测试

该包包含一些测试,可以通过 phpunit 运行。

./vendor/bin/phpunit

致谢

变更日志

有关最近更改的更多信息,请参阅 CHANGELOG

许可

MIT 许可证 (MIT)。有关更多信息,请参阅 许可文件