iamkevinmckee / many-to-many
Easily generate a migration for a many to many relationship
Installs: 1 400
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 1
Forks: 1
Open Issues: 0
Requires
- php: ^7.1|^8.0
- illuminate/support: ^6.0|^7.0|^8.0|^9.0|^10.0
Requires (Dev)
- orchestra/testbench: ^4.0
- phpunit/phpunit: ^8.0
This package is auto-updated.
Last update: 2024-11-04 23:19:22 UTC
README
When you want to make a many to many relationship in Laravel, you need to create a pivot table. This package gives you a command to generate the migration for that pivot table automatically.
Installation
You can install the package via composer:
composer require iamkevinmckee/many-to-many --dev
Usage
When you need to create a pivot table for a many to many relationship, just run the following command:
php artisan many-to-many FirstModel SecondModel
For example:
php artisan many-to-many tag post
This will generate a migration with the following up
method:
public function up() { Schema::create('post_tag', function (Blueprint $table) { $table->unsignedBigInteger('post_id'); $table->unsignedBigInteger('tag_id'); $table->foreign('post_id')->references('id')->on('posts') ->onDelete('cascade'); $table->foreign('tag_id')->references('id')->on('tags') ->onDelete('cascade'); }); }
Then you only need to run the migrate command and add the relationship to the models.
Changelog
Please see CHANGELOG for more information what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email mckee.kevin@gmail.com instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.
Laravel Package Boilerplate
This package was generated using the Laravel Package Boilerplate.