Reputation: 387
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.
Upvotes: 1
Views: 9609
Reputation: 1012
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']);
});
}
Upvotes: 7
Reputation: 4499
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"
Upvotes: 0