autotrof/eloquent-composite-key
最新稳定版本:1.0.0
Composer 安装命令:
composer require autotrof/eloquent-composite-key
包简介
Eloquent Composite Key Support Package
README 文档
README
Package to enable composite key support on Eloquent Models.
Installation
Install it with composer:
composer require thiagoprz/eloquent-composite-key
Usage
Define the primaryKey as an array and use the HasCompositeKey trait on your model class.
<?php
...
use Thiagoprz\CompositeKey\HasCompositeKey;
class User extends Model
{
use HasCompositeKey;
...
protected $primaryKey = ['firstKey', 'secondKey'];
...
}
Using primary keys to find records:
<?php
...
// Returns model instance or null
$user = User::find([
'key_1' => $key1,
'key_2' => $key2,
]);
...
// Throws ModelNotFoundException
$user = User::findOrFail([
'key_1' => $key1,
'key_2' => $key2,
]);
...
The main idea of this package is to allow Laravel projects use composite keys on models despite Eloquent not supporting them officially (see https://laravel.com/docs/8.x/eloquent#composite-primary-keys).
License
统计信息
- 总下载量: 7
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-04-25