Skip to content

Instantly share code, notes, and snippets.

@lednhatkhanh
Created March 8, 2017 15:24
Show Gist options
  • Select an option

  • Save lednhatkhanh/c78ebbcb2801e8f90a5635a93b3853df to your computer and use it in GitHub Desktop.

Select an option

Save lednhatkhanh/c78ebbcb2801e8f90a5635a93b3853df to your computer and use it in GitHub Desktop.
Create trigger with laravel migration
<?php
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class AddFeedbacksTableDeleteTrigger extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
DB::unprepared('CREATE TRIGGER before_feedback_delete
BEFORE DELETE ON feedbacks
FOR EACH ROW
DELETE FROM comments WHERE `feedback_id` = old.id;');
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
DB::unprepared('DROP TRIGGER before_feedback_delete');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment