1

I am new to laravel and I want to know that can't we add two column into existing table using

php artisan make:migration 

at once for Ex. if my users table contain id,user_name and now I want to add two new column like as user_phone and user_email in one

php artisan make:migration add_user_phone_to_users_table add_user_email_to_users_table 

something like that ? I am very sorry If my question is wrong.. I can add new field one by one into two separate migration but want to know is it possible to add two new column to existing table at once. Thanks in advance and I hope I will get a satisfied answer.

2
  • Could you edit your question: split it into text and samples and perhaps provide sample that works for you and base for sample that you are going to create Commented Oct 15, 2018 at 16:48
  • @rudolf_franek I got the answer .thank you I will keep in mind that next time whenever I will ask question I will come up with nice formatted text..Sorry. Commented Oct 15, 2018 at 16:54

2 Answers 2

7

You are right by creating a new migration, php artisan make:migration add_email_and_phone_number_to_users --table=users

In the migration you can add the code for this:

public function up()
{
    Schema::table('users', function (Blueprint $table) {
        $table->string('email')->nullable();
        $table->string('phone_number')->nullable();
    });
}

public function down()
{
    Schema::table('users', function (Blueprint $table) {
        $table->dropColumn(['email', 'phone_number']);
    });
}
Sign up to request clarification or add additional context in comments.

1 Comment

I am so happy.. This is what exactly I want Thank you so much..As well as thank you so much for all.. This is my first question so I am uable to upvote your answer..
0

when adding more columns to an existing table using another migration, you need to define the table

php artisan make:migration name_of_the_migration --table="table_name"

3 Comments

Thanks for the response but my question is can we add two new column to exising table in one statement php artisan make:migration add_user_phone_to_users_table add_uers_email_to_users_table --table="users" Is it possible?
what you need to understand here is, the name of the migration doesn't matter. execute this command and it will create a new migration file and you can add as many columns inside that migration file.
Thanks Thakara Thijs Bouwes answer help me out but thank you too for your great effort..Keep it up..

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.