PHPackages                             cline/variable-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. cline/variable-keys

ActiveLibrary

cline/variable-keys
===================

Laravel Blueprint macros for variable primary key and morph types

2.0.3(2mo ago)06.1k↑55.4%12MITPHPPHP ^8.5.0CI passing

Since Dec 24Pushed 2mo agoCompare

[ Source](https://github.com/faustbrian/variable-keys)[ Packagist](https://packagist.org/packages/cline/variable-keys)[ RSS](/packages/cline-variable-keys/feed)WikiDiscussions 2.x Synced 1mo ago

READMEChangelog (9)Dependencies (11)Versions (15)Used By (12)

[![GitHub Workflow Status](https://github.com/faustbrian/variable-keys/actions/workflows/quality-assurance.yaml/badge.svg)](https://github.com/faustbrian/variable-keys/actions)[![Latest Version on Packagist](https://camo.githubusercontent.com/5272fd9fb1b9e72216b5bf696740e8f134f5d5ed5b6a865841fa6e1d3ca8695a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f636c696e652f7661726961626c652d6b6579732e737667)](https://packagist.org/packages/cline/variable-keys)[![Software License](https://camo.githubusercontent.com/784362b26e4b3546254f1893e778ba64616e362bd6ac791991d2c9e880a3a64e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d677265656e2e737667)](LICENSE.md)[![Total Downloads](https://camo.githubusercontent.com/350957cbf89013e696bd1a9b9bc5963c6818fa18cbd06c3b02a47763b7572a28/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f636c696e652f7661726961626c652d6b6579732e737667)](https://packagist.org/packages/cline/variable-keys)

---

variable-keys
=============

[](#variable-keys)

Laravel Blueprint macros for variable primary key and morph types

Requirements
------------

[](#requirements)

> **Requires [PHP 8.4+](https://php.net/releases/)**

Installation
------------

[](#installation)

```
composer require cline/variable-keys
```

Usage
-----

[](#usage)

```
use Cline\VariableKeys\Enums\PrimaryKeyType;
use Cline\VariableKeys\Enums\MorphType;

$primaryKeyType = PrimaryKeyType::tryFrom(config('database.primary_key_type'))
    ?? PrimaryKeyType::ID;

Schema::create('users', function (Blueprint $table) use ($primaryKeyType) {
    // Clean macro instead of verbose match expression
    $table->variablePrimaryKey($primaryKeyType);

    $table->string('name');
    $table->timestamps();
});

Schema::create('posts', function (Blueprint $table) use ($primaryKeyType) {
    $table->variablePrimaryKey($primaryKeyType);

    // Foreign key that matches the primary key type
    $table->variableForeignKey('user_id', $primaryKeyType)
          ->constrained()
          ->cascadeOnDelete();

    $table->string('title');
    $table->timestamps();
});
```

Documentation
-------------

[](#documentation)

- **[Getting Started](https://docs.cline.sh/variable-keys/getting-started/)** - Installation and basic usage
- **[Primary Keys](https://docs.cline.sh/variable-keys/primary-keys/)** - Configure variable primary keys
- **[Foreign Keys](https://docs.cline.sh/variable-keys/foreign-keys/)** - Manage foreign key relationships
- **[Polymorphic Relations](https://docs.cline.sh/variable-keys/polymorphic-relations/)** - Handle polymorphic relationships
- **[Configuration Patterns](https://docs.cline.sh/variable-keys/configuration-patterns/)** - Centralize key type configuration
- **[API Reference](https://docs.cline.sh/variable-keys/api-reference/)** - Complete API documentation

Change log
----------

[](#change-log)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) and [CODE\_OF\_CONDUCT](CODE_OF_CONDUCT.md) for details.

Security
--------

[](#security)

If you discover any security related issues, please use the [GitHub security reporting form](https://github.com/faustbrian/variable-keys/security) rather than the issue queue.

Credits
-------

[](#credits)

- [Brian Faust](https://github.com/faustbrian)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License. Please see [License File](LICENSE.md) for more information.

###  Health Score

50

—

FairBetter than 96% of packages

Maintenance88

Actively maintained with recent releases

Popularity26

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity60

Established project with proven stability

 Bus Factor1

Top contributor holds 100% 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 ~6 days

Total

14

Last Release

61d ago

Major Versions

1.x-dev → 2.0.02026-03-04

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/22145591?v=4)[Brian Faust](/maintainers/faustbrian)[@faustbrian](https://github.com/faustbrian)

---

Top Contributors

[![faustbrian](https://avatars.githubusercontent.com/u/22145591?v=4)](https://github.com/faustbrian "faustbrian (11 commits)")

---

Tags

php

### Embed Badge

![Health badge](/badges/cline-variable-keys/health.svg)

```
[![Health](https://phpackages.com/badges/cline-variable-keys/health.svg)](https://phpackages.com/packages/cline-variable-keys)
```

PHPackages © 2026

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