diff options
author | msquare <msquare@notrademark.de> | 2019-12-08 11:48:58 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-12-08 11:48:58 +0100 |
commit | a3a938a1210f1bfb2680c25b2bcf53e47444bdba (patch) | |
tree | fd4c13fd9b714c0d8c60b6d3fe3e2fc88b82b717 /db/migrations/Reference.php | |
parent | b540ac93856065ce6e145930b6611e0a0946d646 (diff) | |
parent | 064a1750279be244f86cf24f29749b391b11f1dd (diff) |
Merge pull request #685 from MyIgel/schedule-import
Rebuild Schedule import
Diffstat (limited to 'db/migrations/Reference.php')
-rw-r--r-- | db/migrations/Reference.php | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/db/migrations/Reference.php b/db/migrations/Reference.php index 49a1f9ea..d0550686 100644 --- a/db/migrations/Reference.php +++ b/db/migrations/Reference.php @@ -4,6 +4,7 @@ namespace Engelsystem\Migrations; use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\ColumnDefinition; +use Illuminate\Support\Str; trait Reference { @@ -11,20 +12,25 @@ trait Reference * @param Blueprint $table * @param bool $setPrimary */ - protected function referencesUser(Blueprint $table, $setPrimary = false) + protected function referencesUser(Blueprint $table, bool $setPrimary = false) { - $this->references($table, 'users', 'user_id', $setPrimary); + $this->references($table, 'users', null, $setPrimary); } /** - * @param Blueprint $table - * @param string $targetTable - * @param string $fromColumn - * @param bool $setPrimary + * @param Blueprint $table + * @param string $targetTable + * @param string|null $fromColumn + * @param bool $setPrimary * @return ColumnDefinition */ - protected function references(Blueprint $table, $targetTable, $fromColumn, $setPrimary = false): ColumnDefinition - { + protected function references( + Blueprint $table, + string $targetTable, + ?string $fromColumn = null, + bool $setPrimary = false + ): ColumnDefinition { + $fromColumn = $fromColumn ?? Str::singular($targetTable) . '_id'; $col = $table->unsignedInteger($fromColumn); if ($setPrimary) { |