建立MySQL觸發器

helong3314發表於2021-06-04

模組化開發建立MySQL資料遷移

php artisan module:make-migration create_order_insert_table Blog
use \Illuminate\Support\Facades\DB;

public function up()
{
 DB::unprepared(
  ' CREATE TRIGGER order_insert
 AFTER INSERT on orders FOR EACH ROW BEGIN INSERT INTO order_logs(type,order_no,user_id,admin_id,distribution_id,delivery_id,operation  ) VALUES ("INSERT",new.order_no,new.user_id, 0,0,0,"使用者下單");
 END');

}

/**
 * Reverse the migrations. * * @return void
 */public function down()
{
 DB::unprepared('DROP TRIGGER  IF EXISTS order_insert');
}

執行遷移檔案

  php artisan migrate
本作品採用《CC 協議》,轉載必須註明作者和本文連結

相關文章