|
11 | 11 | use Illuminate\Database\Schema\Grammars\MySqlGrammar;
|
12 | 12 | use Illuminate\Support\Fluent;
|
13 | 13 | use Illuminate\Support\Str;
|
| 14 | +use InvalidArgumentException; |
14 | 15 | use SingleStore\Laravel\Schema\Blueprint as SingleStoreBlueprint;
|
15 | 16 | use SingleStore\Laravel\Schema\Grammar\CompilesKeys;
|
16 | 17 | use SingleStore\Laravel\Schema\Grammar\ModifiesColumns;
|
@@ -185,9 +186,27 @@ protected function compileKey(Blueprint $blueprint, Fluent $command, $type)
|
185 | 186 | */
|
186 | 187 | protected function columnizeWithDirection(array $columns, string $direction)
|
187 | 188 | {
|
| 189 | + if ($columns === array_filter($columns, 'is_array')) { |
| 190 | + $columnNames = array_map(function ($column) { |
| 191 | + return $this->wrap($column[0]); |
| 192 | + }, $columns); |
| 193 | + |
| 194 | + $columnDirections = array_map(function ($column) { |
| 195 | + return $column[1]; |
| 196 | + }, $columns); |
| 197 | + |
| 198 | + return implode(', ', array_map(function ($column, $direction) { |
| 199 | + return "$column $direction"; |
| 200 | + }, $columnNames, $columnDirections)); |
| 201 | + } |
| 202 | + |
188 | 203 | $wrapped = array_map([$this, 'wrap'], $columns);
|
189 | 204 |
|
190 | 205 | return implode(', ', array_map(function ($column) use ($direction) {
|
| 206 | + if (is_array($column)) { |
| 207 | + throw new InvalidArgumentException('You must set the direction for each key column or use the second parameter to set the direction for all key columns'); |
| 208 | + } |
| 209 | + |
191 | 210 | return $column.' '.$direction;
|
192 | 211 | }, $wrapped));
|
193 | 212 | }
|
|
0 commit comments