Laravel 8 更新字段屬性

2021-07-19 11:19 更新

change 方法可以將現(xiàn)有的字段類型修改為新的類型或修改屬性。
比如,你可能想增加。字符串字段的長(zhǎng)度,可以使用 change 方法把 name 字段的長(zhǎng)度從 25 增加到 50:

Schema::table('users', function (Blueprint $table) {
    $table->string('name', 50)->change();
}); 

我們同樣可以使用 nullable 將字段修改為允許為空:

Schema::table('users', function (Blueprint $table) {
    $table->string('name', 50)->nullable()->change();
}); 

注意:只有以下字段類型能被 「修改」:bigInteger、binary、boolean、date、dateTime、dateTimeTz、decimal、integer、json、 longText、mediumText、smallInteger、string、text、time、unsignedBigInteger、unsignedInteger 和 unsignedSmallInteger。

以上內(nèi)容是否對(duì)您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號(hào)
微信公眾號(hào)

編程獅公眾號(hào)