如何在 Laravel 中已经制作的表中添加多列?

Lea*_*ner 7 php laravel

我想在 Laravel 中已经制作的表中添加多个列。如何添加多列?

我不知道如何在我的表中添加列。我一次只能添加一列。

下面给出的是我的迁移表向上功能。

  public function up()
    {
        Schema::create('matches', function (Blueprint $table) {
            $table->increments('id');
            $table->string('sports');
            $table->string('match');
            $table->string('date');
            $table->string('time');
            $table->string('teamA');
           $table->longtext('teamA_flag');
            $table->string('teamB');
               $table->longtext('teamB_flag');
            $table->string('venue');
            $table->string('status');
            $table->timestamps();
        });
    }
Run Code Online (Sandbox Code Playgroud)

这是我的名字是matches 的表。我想使用 Laravel 添加两列。三列的名称是:电子邮件、资格。

我希望在表上添加多个列(匹配项)。我想在 Laravel 中已经制作的表中添加多个列。如何添加多列?

我不知道如何在我的表中添加列。我一次只能添加一列。

Reg*_*ith 11

首先通过创建迁移php artisan make:migration alter_table_matches,打开由命令创建的迁移。

public function up()
{
    Schema::table('matches', function (Blueprint $table) {
        $table->string('email')->nullable()->default(null);
        $table->string('qualification')->nullable()->default(null);
    });
}
Run Code Online (Sandbox Code Playgroud)

然后在向下功能

public function down()
{
    Schema::table('matches', function (Blueprint $table) {
        $table->dropColumn('email');
        $table->dropColumn('qualification');
    });
}
Run Code Online (Sandbox Code Playgroud)


小智 6

你可以运行:

php artisan make:migration add_first_item_and_second_item_and_next_item_to_matches
Run Code Online (Sandbox Code Playgroud)

这将创建一个迁移文件,然后您可以添加:

 public function up()
{
    Schema::table('products', function (Blueprint $table) {
        $table->string('first_item');
        $table->string('second_item');
        $table->string('next_item');
    });
}

public function down()
{
    Schema::table('products', function (Blueprint $table) {
        $table->dropColumn('first_item');
        $table->dropColumn('second_item');
        $table->dropColumn('next_item');
    });
}
Run Code Online (Sandbox Code Playgroud)

我希望这能解决你的问题