josezenem / laravel-make-migration-pivot
Make Laravel pivot tables using the new Laravel 9 closure migrations.
Fund package maintenance!
josezenem
Installs: 36 701
Dependents: 0
Suggesters: 0
Security: 0
Stars: 20
Watchers: 2
Forks: 3
Open Issues: 0
Requires
- php: ^8.0
- illuminate/contracts: ^9.0|^10.0|^11.0
- spatie/laravel-package-tools: ^1.9.2
Requires (Dev)
- nunomaduro/collision: ^6.0
- nunomaduro/larastan: ^2.0.1
- orchestra/testbench: ^7.0|^8.0|^9.0
- pestphp/pest: ^1.21|^2.34
- pestphp/pest-plugin-laravel: ^1.1|^2.3
- phpstan/extension-installer: ^1.1
- phpstan/phpstan-deprecation-rules: ^1.0
- phpstan/phpstan-phpunit: ^1.0
- phpunit/phpunit: ^9.5
README
This will allow you to create pivot table migration files using the new Laravel 9 closure migration format by simply passing two models. Under the hood the system will inspect the two models to generate the pivot table and foreign key names.
php artisan make:pivot Category Blog
Will generate the following migration
return new class extends Migration { public function up() { Schema::create('blog_category', function (Blueprint $table) { $table->foreignIdFor(Blog::class)->constrained()->onDelete('cascade'); $table->foreignIdFor(Category::class)->constrained()->onDelete('cascade'); $table->primary(['blog_id', 'category_id']); $table->index('blog_id'); $table->index('category_id'); }); }
Installation
You can install the package via composer:
composer require josezenem/laravel-make-migration-pivot
Usage
php artisan make:pivot Category Blog
Optionally, you can publish the stubs using
php artisan vendor:publish --tag="laravel-make-migration-pivot-stubs"
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.