Skip to content

Commit 22ec785

Browse files
committed
Add with statement
1 parent 662ac36 commit 22ec785

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

src/Schema/Blueprint/InlinesIndexes.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ protected function inlineCreateIndexStatements($statements)
8181
protected function indexCommands()
8282
{
8383
return $this->commandsNamed(array_merge(
84-
$this->singleStoreIndexes, $this->mysqlIndexes
84+
$this->singleStoreIndexes,
85+
$this->mysqlIndexes
8586
));
8687
}
8788

@@ -116,7 +117,14 @@ protected function addFluentSingleStoreIndexes()
116117
foreach ($this->columns as $column) {
117118
foreach ($this->singleStoreIndexes as $index) {
118119
if (isset($column->{$index})) {
119-
$this->{$index}($column->name, ($column->{$index} === true ? null : $column->{$index}));
120+
$command = $this->{$index}($column->name, ($column->{$index} === true ? null : $column->{$index}));
121+
122+
// Forward with attributes if sortKey
123+
if ($index === 'sortKey' && isset($column->with)) {
124+
$command->with($column->with);
125+
$column->with = null;
126+
}
127+
120128
$column->{$index} = false;
121129
}
122130
}

src/Schema/Grammar/CompilesKeys.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,15 @@ public function compileShardKey(Blueprint $blueprint, Fluent $command)
1717

1818
public function compileSortKey(Blueprint $blueprint, Fluent $command)
1919
{
20+
if (is_array($command->with)) {
21+
$compiled = collect($command->with)->map(
22+
fn ($value, $variable) => "{$variable}={$value}"
23+
)->join(',');
24+
25+
return "sort key({$this->columnize($command->columns)}) with ({$compiled})";
26+
}
27+
28+
2029
return "sort key({$this->columnize($command->columns)})";
2130
}
2231

0 commit comments

Comments
 (0)