From ba87058be0632517dfecb4a6b1921e2a7ac4b888 Mon Sep 17 00:00:00 2001 From: LorenzoPapi <42911751+LorenzoPapi@users.noreply.github.com> Date: Mon, 20 Oct 2025 17:09:22 +0200 Subject: [PATCH] Fix pivot table migration building When the belongstomany attribute was given a special name, the id column type identifying wasn't working and would fall back to the usual integer id, causing errors. Now, by considering as a key the string before the `:`, it should work --- src/Generators/MigrationGenerator.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Generators/MigrationGenerator.php b/src/Generators/MigrationGenerator.php index 46146572..c869e3b7 100644 --- a/src/Generators/MigrationGenerator.php +++ b/src/Generators/MigrationGenerator.php @@ -381,7 +381,8 @@ protected function buildPivotTableDefinition(array $segments, array $models = [] { $definition = ''; foreach ($segments as $segment) { - $column = Str::before(Str::snake($segment), ':'); + $key = Str::before($segment, ":"); + $column = Str::snake($key); $references = 'id'; $on = Str::plural($column); $foreign = Str::singular($column) . '_' . $references; @@ -389,7 +390,7 @@ protected function buildPivotTableDefinition(array $segments, array $models = [] if (config('blueprint.use_constraints')) { $this->hasForeignKeyConstraints = true; - $type = isset($models[$segment]) ? $models[$segment]->idType() : 'id'; + $type = isset($models[$key]) ? $models[$key]->idType() : 'id'; $definition .= $this->buildForeignKey($foreign, $on, $type) . ';' . PHP_EOL; } else { $definition .= $this->generateForeignKeyDefinition($segment, $foreign, $models);