PHPackages                             dyrynda/eloquent-composite-primary-keys - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. dyrynda/eloquent-composite-primary-keys

ActiveLibrary

dyrynda/eloquent-composite-primary-keys
=======================================

Offers composite primary keys on Eloquent models

2.0.0(6y ago)19MITPHP

Since Oct 23Pushed 6y agoCompare

[ Source](https://github.com/michaeldyrynda/eloquent-composite-primary-keys)[ Packagist](https://packagist.org/packages/dyrynda/eloquent-composite-primary-keys)[ RSS](/packages/dyrynda-eloquent-composite-primary-keys/feed)WikiDiscussions master Synced yesterday

READMEChangelog (1)Dependencies (1)Versions (3)Used By (0)

Eloquent Composite Primary Keys
===============================

[](#eloquent-composite-primary-keys)

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](https://stackoverflow.com/a/36995763/526501) and has also been released in a package with more than this functionality. I needed a separate package for just this purpose.

This package has been forked from [Coen Jacobs](https://github.com/coenjacobs/eloquent-composite-primary-keys) as we have a need for it moving forward (Laravel 6.0+), but they've archived the project.

Install
-------

[](#install)

Install this package through Composer:

```
composer require dyrynda/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 Dyrynda\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');
```

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity64

Established project with proven stability

 Bus Factor1

Top contributor holds 57.1% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~704 days

Total

2

Last Release

2419d ago

Major Versions

1.0.0 → 2.0.02019-09-28

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/558441?v=4)[Michael Dyrynda](/maintainers/michaeldyrynda)[@michaeldyrynda](https://github.com/michaeldyrynda)

---

Top Contributors

[![coenjacobs](https://avatars.githubusercontent.com/u/245703?v=4)](https://github.com/coenjacobs "coenjacobs (4 commits)")[![michaeldyrynda](https://avatars.githubusercontent.com/u/558441?v=4)](https://github.com/michaeldyrynda "michaeldyrynda (2 commits)")[![noxify](https://avatars.githubusercontent.com/u/521777?v=4)](https://github.com/noxify "noxify (1 commits)")

### Embed Badge

![Health badge](/badges/dyrynda-eloquent-composite-primary-keys/health.svg)

```
[![Health](https://phpackages.com/badges/dyrynda-eloquent-composite-primary-keys/health.svg)](https://phpackages.com/packages/dyrynda-eloquent-composite-primary-keys)
```

###  Alternatives

[larastan/larastan

Larastan - Discover bugs in your code without running it. A phpstan/phpstan extension for Laravel

6.4k43.5M5.2k](/packages/larastan-larastan)[owen-it/laravel-auditing

Audit changes of your Eloquent models in Laravel

3.4k33.0M95](/packages/owen-it-laravel-auditing)[fumeapp/modeltyper

Generate TypeScript interfaces from Laravel Models

196277.9k](/packages/fumeapp-modeltyper)[casbin/laravel-authz

An authorization library that supports access control models like ACL, RBAC, ABAC in Laravel.

324339.9k4](/packages/casbin-laravel-authz)[pressbooks/pressbooks

Pressbooks is an open source book publishing tool built on a WordPress multisite platform. Pressbooks outputs books in multiple formats, including PDF, EPUB, web, and a variety of XML flavours, using a theming/templating system, driven by CSS.

44643.1k1](/packages/pressbooks-pressbooks)[illuminatech/balance

Provides support for Balance accounting system based on debit and credit principle

16137.4k](/packages/illuminatech-balance)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
