From 82600ba597db78261829e1a5d4c377dbc316b498 Mon Sep 17 00:00:00 2001 From: LT Date: Tue, 24 Dec 2024 16:32:32 +0300 Subject: [PATCH 1/2] feat: MakeResourceCommand with type option Issue #1399 --- src/Laravel/src/Commands/MakeResourceCommand.php | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/Laravel/src/Commands/MakeResourceCommand.php b/src/Laravel/src/Commands/MakeResourceCommand.php index 23fb46096..63fca6e57 100644 --- a/src/Laravel/src/Commands/MakeResourceCommand.php +++ b/src/Laravel/src/Commands/MakeResourceCommand.php @@ -13,7 +13,7 @@ #[AsCommand(name: 'moonshine:resource')] class MakeResourceCommand extends MoonShineCommand { - protected $signature = 'moonshine:resource {name?} {--m|model=} {--t|title=} {--test} {--pest}'; + protected $signature = 'moonshine:resource {name?} {--type=} {--m|model=} {--t|title=} {--test} {--pest}'; protected $description = 'Create resource'; @@ -41,11 +41,18 @@ public function handle(): int $this->makeDir($resourcesDir); - $stub = select('Resource type', [ + $types = [ 'ModelResourceDefault' => 'Default model resource', 'ModelResourceWithPages' => 'Model resource with pages', 'Resource' => 'Empty resource', - ], 'ModelResourceDefault'); + ]; + + if($type = $this->option('type')) { + $keys = array_keys($types); + $stub = $keys[$type-1] ?? $keys[0]; + } else { + $stub = select('Resource type', $types, 'ModelResourceDefault'); + } $replace = [ '{namespace}' => moonshineConfig()->getNamespace('\Resources'), From f5aa9745860800b9fe1ec522764ff3a0f7a6654b Mon Sep 17 00:00:00 2001 From: lee-to Date: Tue, 24 Dec 2024 13:32:59 +0000 Subject: [PATCH 2/2] Fix styling --- src/Laravel/src/Commands/MakeResourceCommand.php | 4 ++-- src/Laravel/src/Http/Requests/MoonShineFormRequest.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Laravel/src/Commands/MakeResourceCommand.php b/src/Laravel/src/Commands/MakeResourceCommand.php index 63fca6e57..5c14880a5 100644 --- a/src/Laravel/src/Commands/MakeResourceCommand.php +++ b/src/Laravel/src/Commands/MakeResourceCommand.php @@ -47,9 +47,9 @@ public function handle(): int 'Resource' => 'Empty resource', ]; - if($type = $this->option('type')) { + if ($type = $this->option('type')) { $keys = array_keys($types); - $stub = $keys[$type-1] ?? $keys[0]; + $stub = $keys[$type - 1] ?? $keys[0]; } else { $stub = select('Resource type', $types, 'ModelResourceDefault'); } diff --git a/src/Laravel/src/Http/Requests/MoonShineFormRequest.php b/src/Laravel/src/Http/Requests/MoonShineFormRequest.php index edaf06caa..dbead8c9c 100644 --- a/src/Laravel/src/Http/Requests/MoonShineFormRequest.php +++ b/src/Laravel/src/Http/Requests/MoonShineFormRequest.php @@ -38,7 +38,7 @@ public function messages(): array $messages = __('moonshine::validation'); return array_merge( - is_array($messages) ? $messages : [], + \is_array($messages) ? $messages : [], $this->getResource()?->validationMessages() ?? [] ); }