New

Just launched: Vueblocks, a brand-new search engine for Vue packages! Explore Vueblocks →

josezenem/laravel-make-migration-pivot

Make Laravel pivot tables using the new Laravel 9 closure migrations.
91,669 20
Install
composer require josezenem/laravel-make-migration-pivot
Latest Version:1.3.2
PHP:^8.0
Laravel:9 – 12
License:MIT
Last Updated:Apr 20, 2026
Links: GitHub  ·  Packagist
Maintainer: josezenem

Make Laravel Pivot Tables using the new Laravel 9 closure migration format

Latest Version on Packagist Check & fix styling Total Downloads

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.

Related Packages

josezenem/laravel-slugidable

A package for Laravel that creates slugs for Eloquent models based on title and...

68,866 11
doctrine/dbal

Powerful PHP database abstraction layer (DBAL) with many features for database s...

648,266,899 9,701
laravel/framework

The Laravel Framework.

604,216,237 34,982
laravel/tinker

Powerful REPL for the Laravel framework.

512,508,631 7,443

Version History

Version Released PHP Laravel License
1.3.2 ^8.0 ^9.0|^10.0|^11.0|^12.0 MIT
1.3.1 ^8.0 ^9.0|^10.0|^11.0|^12.0 MIT
1.3.0 ^8.0 ^9.0|^10.0|^11.0|^12.0 MIT
1.2.0 ^8.0 ^9.0|^10.0|^11.0 MIT
1.1.0 ^8.0 ^9.0|^10.0 MIT