When adding new columns...

Опубликовано: 01 Апрель 2026
на канале: Metaphorically Speaking
275
12

When you want to add a bunch of new columns, but you want them all to start AFTER a particular column... it can be quite repetitive calling the after() method.

Also, it's quite prone to error, too.

If, during development, you change the name of the column - you need to ensure you have also updated all those calls.

But, we can do better.

Because it's possible to call the after() method on the table blueprint itself!

When doing this, all the new columns being defined will be after the specified column and will also retain the order in which they were added.

This is pretty neat.

---

Website: https://acairns.co.uk
Twitter:   / andrewcairns  
Patreon:   / metaphoricallyspeaking  
Discord: https://acairns.co.uk/discord
Substack: https://acairns.substack.com

#laravel #php