2017年9月27日 星期三

Laravel ,softdelete


//下指令
php artisan make:migration add_deleted_at_column_to_posts_tables --table=posts


資料夾:database/migrations裡面多一個檔案



檔名:日期_編號_add_deleted_at_column_to_posts_tables.php



<?php

//檔案:日期_編號_add_deleted_at_column_to_posts_tables.php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class AddDeletedAtColumnToPostsTables extends Migration
{
/**
* Run the migrations.
*
* @return void
*/

public function up()
{
Schema::table('posts', function (Blueprint $table) {
//
});
}

/**
* Reverse the migrations.
*
* @return void
*/

public function down()
{
Schema::table('posts', function (Blueprint $table) {
//
});
}
}


 





 



<?php
//檔案:日期_編號_add_deleted_at_column_to_posts_tables.php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class AddDeletedAtColumnToPostsTables extends Migration
{
public function up()
{
Schema::table('posts', function (Blueprint $table) {

$table->softDeletes();
});
}
public function down()
{
Schema::table('posts', function (Blueprint $table) {
$table->dropColumn('deleted_at');
});
}
}


//下指令
php artisan migrate


資料庫多一個欄位叫deleted_at



 



沒有留言:

張貼留言