Created
March 8, 2017 15:24
-
-
Save lednhatkhanh/c78ebbcb2801e8f90a5635a93b3853df to your computer and use it in GitHub Desktop.
Create trigger with laravel migration
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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