Renaming a Column Using Laravel Migrations


Committed to the LaraBrain by: wjgilmore (@wjgilmore) at October 29, 2015 11:37 am

Renaming columns using Laravel migrations is easy thanks to memorable syntax

Laravel migrations offer a fantastically convenient solution for evolving your database over time. Even so I often wind up searching for syntax documentation on almost every occasion in which I want to create a new migration. In particular I seem to forget with regularity how to rename a column, which is ironic given this is perhaps the most memorable syntax of all:

public function up()
    Schema::table('tips', function ($table) {
        $table->renameColumn('description', 'oneline');

One gotcha associated with this particular migrations feature is it isn't available right out of the box. You'll need to add the doctrine/dbal package to your project:

$ composer require doctrine/dbal