本系列文的環境狀態,可點擊此連結後花園環境參考
統整下列名(欄名)能用的方式,各會有 up() 跟 down() 的部份。
Terminal 輸入指令
$ php artisan make:migration add_new_cloumn_flowers
路徑:database/migrations/2019_10_17_081544_add_new_cloumn_flowers.php
放入下列程式碼。
public function up()
{
Schema::table('flowers', function (Blueprint $table)
{
$table->string('like')->nullable();
});
}
public function down()
{
Schema::table('flowers', function(Blueprint $table)
{
$table->dropColumn('like');
});
}
Terminal 輸入指令
$ php artisan migrate
若要有修改或刪除功能,需在 Terminal 輸入此指令啓用,不然會無法 migrate
$ composer require doctrine/dbal
繼續輸入下列指令
$ php artisan make:migration put_cloumn_name_flowers
路徑:database/migrations/2019_10_17_082851_put_name_cloumn_flowers.php
放入下列程式碼
public function up()
{
Schema::table('flowers', function (Blueprint $table)
{
$table->renameColumn('like','love');
});
}
public function down()
{
Schema::table('flowers', function (Blueprint $table)
{
$table->renameColumn('love','like');
});
}
Terminal 輸入指令
$ php artisan migrate
在 Terminal 輸入指令
$ php artisan make:migration delete_cloumn_flowers
路徑:database/migrations/2019_10_17_092515_delete_cloumn_flowers.php
放入下列程式碼
public function up()
{
schema::table('flowers', function (Blueprint $table) {
$table->dropColumn('love');
});
}
public function down()
{
schema::table('flowers', function (Blueprint $table) {
$table->string('love')->nullable();
});
}
Terminal 輸入指令
$ php artisan migrate
參考連結:
❁ Laravel 官方 - Database: Migrations