From 951828a4f1175f99666a48629ea125640cc7c598 Mon Sep 17 00:00:00 2001 From: Igor Scheller Date: Sat, 10 Nov 2018 20:42:48 +0100 Subject: Migration: Moved reference method to trait --- db/migrations/Reference.php | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 db/migrations/Reference.php (limited to 'db/migrations/Reference.php') diff --git a/db/migrations/Reference.php b/db/migrations/Reference.php new file mode 100644 index 00000000..4c35b59b --- /dev/null +++ b/db/migrations/Reference.php @@ -0,0 +1,36 @@ +references($table, 'users', 'user_id', $setPrimary); + } + + /** + * @param Blueprint $table + * @param string $targetTable + * @param string $fromColumn + * @param bool $setPrimary + */ + protected function references(Blueprint $table, $targetTable, $fromColumn, $setPrimary = false) + { + $table->unsignedInteger($fromColumn); + + if ($setPrimary) { + $table->primary($fromColumn); + } + + $table->foreign($fromColumn) + ->references('id')->on($targetTable) + ->onDelete('cascade'); + } +} -- cgit v1.3.1