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.
Laravel Blueprint macros for variable primary key and morph types
Requires PHP 8.4+
composer require cline/variable-keys
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();
});
Please see CHANGELOG for more information on what has changed recently.
Please see CONTRIBUTING and CODE_OF_CONDUCT for details.
If you discover any security related issues, please use the GitHub security reporting form rather than the issue queue.
The MIT License. Please see License File for more information.
How can I help you explore Laravel packages today?