Answers for "laravel create trigger migration"

PHP
2

laravel create trigger migration

<?php

use Illuminate\Database\Migrations\Migration;

class CreateTrigger extends Migration
{
    public function up()
    {
        DB::unprepared('
                CREATE TRIGGER tr_after_main_insert AFTER INSERT ON `main` FOR EACH ROW
                    BEGIN
                        INSERT INTO `test`(`new_id`, `type`, `value`, `created_at`) VALUES (NEW.id, NEW.type, 1, NOW());
                    END
                ');
    }

    public function down()
    {
        DB::unprepared('DROP TRIGGER `tr_after_main_insert`');
    }
}
Posted by: Guest on June-23-2021

Code answers related to "laravel create trigger migration"

Browse Popular Code Answers by Language