New

Just launched: Vueblocks, a brand-new search engine for Vue packages! Explore Vueblocks →

cline/variable-keys

Laravel Blueprint macros for variable primary key and morph types
23,466
php
Install
composer require cline/variable-keys
Latest Version:2.0.3
PHP:^8.5.0
Laravel:10 – 13
License:MIT
Last Updated:Mar 18, 2026
Links: GitHub  ·  Packagist
Maintainer: faustbrian

GitHub Workflow Status Latest Version on Packagist Software License Total Downloads


variable-keys

Laravel Blueprint macros for variable primary key and morph types

Requirements

Requires PHP 8.4+

Installation

composer require cline/variable-keys

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

Change log

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING and CODE_OF_CONDUCT for details.

Security

If you discover any security related issues, please use the GitHub security reporting form rather than the issue queue.

Credits

License

The MIT License. Please see License File for more information.

Related Packages

valorin/random

Random is a simple helper package designed to make it easy to generate a range o...

423,305 234
php
cline/struct

Lean, attribute-driven Laravel data objects with explicit validation and Eloquen...

18,346 0
php
cline/toggl

Advanced feature flag management with strategies, time bombs, and groups

12,635 0
php
cline/sequencer

Sequential migration and operation orchestration for Laravel

11,736 0
php
viodev/laravel-db-bulk

Laravel helper for bulk insert/update records in batches.

10,392 0
php

Version History

Version Released PHP Laravel License
2.0.3 ^8.5.0 ^10.0 || ^11.0 || ^12.0 || ^13.0 MIT
2.0.2 ^8.5.0 ^10.0 || ^11.0 || ^12.0 || ^13.0 MIT
2.0.1 ^8.5.0 ^10.0 || ^11.0 || ^12.0 || ^13.0 MIT
2.0.0 ^8.5.0 ^10.0 || ^11.0 || ^12.0 || ^13.0 MIT
1.4.3 ^8.5.0 ^10.0 || ^11.0 || ^12.0 MIT