diff options
author | Igor Scheller <igor.scheller@igorshp.de> | 2018-11-10 20:42:48 +0100 |
---|---|---|
committer | msquare <msquare@notrademark.de> | 2018-12-02 12:53:31 +0100 |
commit | 951828a4f1175f99666a48629ea125640cc7c598 (patch) | |
tree | 1bba1433ec048de92340471907bd8edfa07f5c93 /db/migrations/Reference.php | |
parent | 720b46f60f1033bc2249b846363f883fa3644ab8 (diff) |
Migration: Moved reference method to trait
Diffstat (limited to 'db/migrations/Reference.php')
-rw-r--r-- | db/migrations/Reference.php | 36 |
1 files changed, 36 insertions, 0 deletions
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 @@ +<?php + +namespace Engelsystem\Migrations; + +use Illuminate\Database\Schema\Blueprint; + +trait Reference +{ + /** + * @param Blueprint $table + * @param bool $setPrimary + */ + protected function referencesUser(Blueprint $table, $setPrimary = true) + { + $this->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'); + } +} |