ogestor/eloquent-composite-primary-keys
Composer 安装命令:
composer require ogestor/eloquent-composite-primary-keys
包简介
Offers composite primary keys on Eloquent models
README 文档
README
A single trait to implement in your Eloquent models to support composite primary keys. The Laravel Schema builder supports creating composite primary keys, but Eloquent models don't support it.
This package is largely inspired by suggested code on Stack Exchange and has also been released in a package with more than this functionality. I needed a separate package for just this purpose.
Install
Install this package through Composer:
composer require ogestor/eloquent-composite-primary-keys
Make sure you have a database schema that supports composite primary keys, for example via a migration:
Schema::create('products', function (Blueprint $table) { $table->integer('first_key'); $table->integer('another_key'); $table->primary(['first_key', 'another_key']); $table->timestamps(); });
Use the trait on the Eloquent model you wish to have composite primary keys on:
namespace App; use Illuminate\Database\Eloquent\Model; use CoenJacobs\EloquentCompositePrimaryKeys\HasCompositePrimaryKey; class Product extends Model { use HasCompositePrimaryKey;
Next, you set the $primaryKey property on your Eloquent model to an array containing the field names that together form your composite primary key:
protected $primaryKey = array('first_key', 'another_key');
统计信息
- 总下载量: 3
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-11-26