Skip to content

Commit

Permalink
feat: MakeResourceCommand with type option
Browse files Browse the repository at this point in the history
Issue #1399
  • Loading branch information
lee-to committed Dec 24, 2024
1 parent 1c6d480 commit 82600ba
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/Laravel/src/Commands/MakeResourceCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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'),
Expand Down

0 comments on commit 82600ba

Please sign in to comment.