Skip to content

Commit da3ffba

Browse files
authored
Search in rest command (#203)
1 parent d454e42 commit da3ffba

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

src/Console/Commands/ControllerMakeCommand.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
use Symfony\Component\Console\Output\OutputInterface;
1313
use Symfony\Component\Finder\Finder;
1414

15-
use function Laravel\Prompts\select;
15+
use function Laravel\Prompts\search;
1616

1717
#[AsCommand(name: 'rest:controller')]
1818
class ControllerMakeCommand extends GeneratorCommand
@@ -156,9 +156,12 @@ protected function afterPromptingForMissingArguments(InputInterface $input, Outp
156156
if ($this->didReceiveOptions($input)) {
157157
return;
158158
}
159-
$resource = select(
159+
160+
$resource = search(
160161
'What resource should this resource relies to? (Optional)',
161-
$this->possibleResources()
162+
fn ($value) => strlen($value) > 0
163+
? array_filter($this->possibleResources(), fn ($resource) => stripos($resource, $value) !== false)
164+
: $this->possibleResources()
162165
);
163166

164167
if ($resource) {

src/Console/Commands/ResourceMakeCommand.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
use Symfony\Component\Console\Input\InputOption;
1010
use Symfony\Component\Console\Output\OutputInterface;
1111

12-
use function Laravel\Prompts\select;
12+
use function Laravel\Prompts\search;
1313

1414
#[AsCommand(name: 'rest:resource')]
1515
class ResourceMakeCommand extends GeneratorCommand
@@ -152,9 +152,11 @@ protected function afterPromptingForMissingArguments(InputInterface $input, Outp
152152
return;
153153
}
154154

155-
$model = select(
155+
$model = search(
156156
'What model should this resource relies to? (Optional)',
157-
$this->possibleModels(),
157+
fn ($value) => strlen($value) > 0
158+
? array_filter($this->possibleModels(), fn ($model) => stripos($model, $value) !== false)
159+
: $this->possibleModels()
158160
);
159161

160162
if ($model) {

0 commit comments

Comments
 (0)