Laravel Migration – How to Add New Column in Existing Table ?

Laravel Migration – How to Add New Column in Existing Table ?

In this post we will give you information about Laravel Migration – How to Add New Column in Existing Table ?. Hear we will give you detail about Laravel Migration – How to Add New Column in Existing Table ?And how to use it also give you demo for it if it is necessary.

Hi Artisan,

Today, laravel migration add column to existing table is our main topic. let’s discuss about laravel add new column to existing table migration. you will learn add column to table migration laravel. you’ll learn laravel migration add column to table.

Here, i will give you full example how to add new column using laravel migration. we will add new column on existing table. so let’s see bellow full example step by step.

Migration for main table:

<?php

use IlluminateSupportFacadesSchema;

use IlluminateDatabaseSchemaBlueprint;

use IlluminateDatabaseMigrationsMigration;

class CreatePostsTable extends Migration

{

/**

* Run the migrations.

*

* @return void

*/

public function up()

{

Schema::create('posts', function (Blueprint $table) {

$table->bigIncrements('id');

$table->string('title');

$table->text('body');

$table->boolean('is_publish')->default(0);

$table->timestamps();

});

}

/**

* Reverse the migrations.

*

* @return void

*/

public function down()

{

Schema::dropIfExists('posts');

}

}

Add Column using Migration:

Also see:How to Change Table Name using Laravel Migration?

<?php

use IlluminateSupportFacadesSchema;

use IlluminateDatabaseSchemaBlueprint;

use IlluminateDatabaseMigrationsMigration;

class ChangePostsTableColumn extends Migration

{

/**

* Run the migrations.

*

* @return void

*/

public function up()

{

Schema::table('posts', function (Blueprint $table) {

$table->integer('auther_id');

$table->string('note');

});

}

/**

* Reverse the migrations.

*

* @return void

*/

public function down()

{

}

}

I hope it can help you…

Hope this code and post will helped you for implement Laravel Migration – How to Add New Column in Existing Table ?. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs

For More Info See :: laravel And github

Leave a Comment

Your email address will not be published. Required fields are marked *

  +  47  =  48

We're accepting well-written guest posts and this is a great opportunity to collaborate : Contact US