• Reading time ~ 1 min
  • 25.08.2022

Laravel 8.27 introduces a new after method on the Blueprint migration instance which allows you to add multiple new columns after an existing column at the same time:

Previously, you'd have to reference each new column to get the order correct—you can see that the after cleans up this code nicely:

Schema::table('customers', function ($table) {
    $table->string('address_line1')->after('password');
    $table->string('address_line2')->after('address_line1');
    $table->string('city')->after('address_line2');
});

While the original code isn't difficult to write, the after() method avoids repetitive after() calls for each subsequent new column and gives a nice abstraction for adding multiple columns. Pairing this with Laravel 8 migration squashing and model factory classes, Laravel continues to improve what is already some of the best migration tools available in any framework.

If you'd like to learn more about how Laravel implemented this feature, check out Pull Request #36145. Adding multiple columns after an existing column is available with the release of v8.27.0.

Comments

No comments yet
Yurij Finiv

Yurij Finiv

Full stack

ABOUT

Professional Fullstack Developer with extensive experience in website and desktop application development. Proficient in a wide range of tools and technologies, including Bootstrap, Tailwind, HTML5, CSS3, PUG, JavaScript, Alpine.js, jQuery, PHP, MODX, and Node.js. Skilled in website development using Symfony, MODX, and Laravel. Experience: Contributed to the development and translation of MODX3 i...

About author CrazyBoy49z
WORK EXPERIENCE
Contact
Ukraine, Lutsk
+380979856297