Skip to content

Commit e37afcf

Browse files
authored
Merge pull request #1990 from alissn/SynchronizationModelShowCommand
Synchronize `module:model-show` Command with `model:show` Command in Laravel Framework
2 parents 66c3eb2 + 642b3e9 commit e37afcf

File tree

2 files changed

+14
-46
lines changed

2 files changed

+14
-46
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"mockery/mockery": "^1.6",
3030
"orchestra/testbench": "^v9.0",
3131
"friendsofphp/php-cs-fixer": "^v3.52",
32-
"laravel/framework": "^v11.0",
32+
"laravel/framework": "^v11.33",
3333
"laravel/pint": "^1.16",
3434
"spatie/phpunit-snapshot-assertions": "^5.0",
3535
"phpstan/phpstan": "^1.4"

src/Commands/Actions/ModelShowCommand.php

Lines changed: 13 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,8 @@
88
use Illuminate\Support\Facades\File;
99
use Illuminate\Support\Str;
1010
use Symfony\Component\Console\Attribute\AsCommand;
11-
use Symfony\Component\Console\Input\InputInterface;
12-
use Symfony\Component\Console\Output\OutputInterface;
1311

1412
use function Laravel\Prompts\search;
15-
use function Laravel\Prompts\select;
1613

1714
#[AsCommand('module:model-show', 'Show information about an Eloquent model in modules')]
1815
class ModelShowCommand extends ShowModelCommand implements PromptsForMissingInput
@@ -40,32 +37,6 @@ class ModelShowCommand extends ShowModelCommand implements PromptsForMissingInpu
4037
{--database= : The database connection to use}
4138
{--json : Output the model as JSON}';
4239

43-
/**
44-
* Qualify the given model class base name.
45-
*
46-
* @see \Illuminate\Console\GeneratorCommand
47-
*/
48-
protected function qualifyModel(string $model): string
49-
{
50-
if (str_contains($model, '\\') && class_exists($model)) {
51-
return $model;
52-
}
53-
54-
$modelPaths = $this->findModels($model);
55-
56-
if ($modelPaths->count() == 0) {
57-
return $model;
58-
} elseif ($modelPaths->count() == 1) {
59-
return $this->formatModuleNamespace($modelPaths->first());
60-
}
61-
62-
return select(
63-
label: 'Select Model',
64-
options: $modelPaths,
65-
required: 'You must select at least one model',
66-
);
67-
}
68-
6940
private function formatModuleNamespace(string $path): string
7041
{
7142
return
@@ -90,22 +61,19 @@ public function findModels(string $model): Collection
9061
->map($this->formatModuleNamespace(...));
9162
}
9263

93-
protected function promptForMissingArguments(InputInterface $input, OutputInterface $output): void
64+
protected function promptForMissingArgumentsUsing(): array
9465
{
95-
$selected_item = search(
96-
label: 'Select Model',
97-
options: function (string $search_value) {
98-
return $this->findModels(
99-
Str::of($search_value)->wrap('', '*')
100-
)->toArray();
101-
},
102-
placeholder: 'type some thing',
103-
required: 'You must select one Model',
104-
);
105-
106-
$input->setArgument(
107-
name: 'model',
108-
value: $selected_item
109-
);
66+
return [
67+
'model' => fn () => search(
68+
label: 'Select Model',
69+
options: function (string $search_value) {
70+
return $this->findModels(
71+
Str::of($search_value)->wrap('', '*')
72+
)->toArray();
73+
},
74+
placeholder: 'type some thing',
75+
required: 'You must select one Model',
76+
),
77+
];
11078
}
11179
}

0 commit comments

Comments
 (0)