diff options
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) { |