Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Variable Keys Laravel Package

cline/variable-keys

Laravel Blueprint macros for variable primary key types, matching foreign keys, and polymorphic morph types. Easily switch between id/uuid/ulid (and more) via enums/config to keep migrations consistent across models and relationships.

View on GitHub
Deep Wiki
Context7

Product Decisions This Supports

  • Schema Flexibility for Multi-Tenant/SaaS: Enables seamless adoption of UUIDs or ULIDs as primary keys for tenant-isolated tables, reducing ID collisions and improving scalability. Supports dynamic key type selection per environment (e.g., integer for staging, uuid for production).
  • Polymorphic Table Standardization: Simplifies shared tables (e.g., comments, audit_logs) by aligning polymorphic key types with Laravel conventions, reducing edge cases in morphTo/morphWith relationships.
  • Migration Efficiency: Eliminates repetitive match logic in migrations when switching key types (e.g., from id() to uuid()), accelerating schema evolution for greenfield projects or large refactors.
  • Configuration-Driven Architecture: Centralizes key type decisions (e.g., via .env or config) to enforce consistency across microservices or modular monoliths, reducing merge conflicts in shared repositories.
  • Roadmap for Multi-Database Support: Future-proofs the architecture for databases with divergent key requirements (e.g., PostgreSQL UUIDs vs. MySQL auto-increment), enabling database-agnostic Laravel applications.
  • Build vs. Buy: Avoids reinventing custom migration macros or relying on fragmented packages (e.g., laravel-uuid + spatie/laravel-activitylog) for basic key type flexibility, reducing technical debt.

When to Consider This Package

  • Adopt if:
    • Your application requires dynamic primary key types (e.g., UUIDs for security, integers for performance) across tables or environments.
    • You manage polymorphic relationships (e.g., comments, audit_logs) and want to avoid manual morphMap adjustments for non-integer keys.
    • Your team frequently refactors migrations or switches key types (e.g., from id to uuid), and repetitive match logic is a pain point.
    • You’re building a multi-tenant SaaS or distributed system where key collisions or tenant isolation are concerns.
    • You prioritize cleaner migrations and reduced boilerplate over minimal dependencies.
  • Avoid if:
    • Your schema uses a single, static primary key type (e.g., auto-increment integers) with no plans to change.
    • You’re locked into a legacy database with rigid constraints (e.g., mixed UUIDs and integers) that can’t be normalized.
    • Your project targets PHP <8.4 or Laravel <10, as the package enforces these minimums.
    • You prefer manual control over migrations and reject abstraction layers (e.g., for auditability or custom logic).
  • Consider alternatives if:
    • You need advanced UUID features (e.g., time-based, namespaced generation)—combine with ramsey/uuid or webpatser/laravel-uuid.
    • Your use case involves non-standard morph maps (e.g., custom polymorphic keys)—extend Laravel’s MorphMap directly.
    • You’re using non-relational databases (e.g., MongoDB)—this package is SQL-focused and assumes relational constraints.

How to Pitch It (Stakeholders)

For Executives: "This package lets us standardize how our database keys work—whether they’re simple numbers or unique IDs—without rewriting migrations every time we add a new table. It cuts down on errors from mismatched foreign keys and makes it easier to switch key types later if we need to (e.g., for security or scalability). For example, if we later decide to use UUIDs for all user IDs to prevent collisions in a multi-tenant system, we can flip a config switch and let the package handle the rest. This saves dev time, reduces bugs, and keeps our schema flexible for future needs."

For Engineers: *"variable-keys replaces verbose match expressions in migrations with clean macros like $table->variablePrimaryKey() and $table->variableForeignKey(). It handles:

  • Dynamic primary keys: Define once in config (e.g., uuid, integer, string) and reuse across migrations.
  • Automatic foreign key alignment: Ensures foreign keys match parent table key types, eliminating schema drift.
  • Polymorphic table support: Works seamlessly with morphTo/morphWith for shared tables like comments or audit_logs.
  • Zero runtime overhead: Just Laravel Blueprint macros under the hood—no magic, no black boxes.

Perfect for:

  • Projects where key types might evolve (e.g., SaaS, shared audit tables).
  • Teams tired of copy-pasting match logic for every migration.
  • Applications needing UUIDs or non-integer keys without reinventing the wheel.

Trade-offs:

  • Requires PHP 8.4+ and Laravel 10+ (but worth it for the features).
  • Adds a thin abstraction layer—ideal if you trust Laravel’s Blueprint system."* For PMs: "This is a low-risk, high-reward package for teams that want to future-proof their database schema. It’s not a silver bullet for every use case, but if you’re building something that might need flexible key types (e.g., multi-tenant, polymorphic, or high-scale), it’s a no-brainer. The time saved on migrations and the consistency gained across tables justify the adoption effort."
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
emuniq/filament-browser-notifications
syriable/filament-translator
hungnm28/livewire-form
wenprise/eloquent
crudly/encrypted
fadion/bouncy
cuci/prototurk-sdk
gos/pubsub-router-bundle
cuci/prototurk-sdk-symfony
clementtalleu/easyadmin-markdown-bundle
codeflextech/permission-manager
karnoweb/livewire-datepicker
sayedenam/sayed-dashboard
milito/query-filter
apiboxsym/user-bundle
apiboxsym/health-check-bundle
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui