cline / variable-keys
Laravel Blueprint macros for variable primary key and morph types
Installs: 10
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/cline/variable-keys
Requires
- php: ^8.5.0
- illuminate/database: ^12.0
- spatie/laravel-package-tools: ^1.16
Requires (Dev)
- cline/coding-standard: ^1.5.6
- orchestra/testbench: ^10.8
- symfony/var-dumper: ^7.4.0
README
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
- Getting Started - Installation and basic usage
- Primary Keys - Configure variable primary keys
- Foreign Keys - Manage foreign key relationships
- Polymorphic Relations - Handle polymorphic relationships
- Configuration Patterns - Centralize key type configuration
- API Reference - Complete API 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.