Skip to content

Commit

Permalink
fix: Make Resource with policy
Browse files Browse the repository at this point in the history
  • Loading branch information
lee-to committed Dec 26, 2024
1 parent 374ef0d commit 5f4bcc5
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
9 changes: 8 additions & 1 deletion 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} {--p|policy}';
protected $signature = 'moonshine:resource {name?} {--type=} {--m|model=} {--t|title=} {--test} {--pest} {--p|policy}';

protected $description = 'Create resource';

Expand Down Expand Up @@ -54,10 +54,17 @@ public function handle(): int
$stub = select('Resource type', $types, 'ModelResourceDefault');
}

$properties = '';

if($this->option('policy')) {
$properties .= PHP_EOL . str_repeat(' ', 4) . 'protected bool $withPolicy = true;' . PHP_EOL;
}

$replace = [
'{namespace}' => moonshineConfig()->getNamespace('\Resources'),
'{model-namespace}' => $model,
'{model}' => class_basename($model),
'{properties}' => $properties,
'DummyTitle' => $title,
'Dummy' => $name,
];
Expand Down
2 changes: 1 addition & 1 deletion src/Laravel/stubs/ModelResourceDefault.stub
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class DummyResource extends ModelResource
protected string $model = {model}::class;

protected string $title = 'DummyTitle';

{properties}
/**
* @return list<FieldContract>
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Laravel/stubs/ModelResourceWithPages.stub
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class DummyResource extends ModelResource
protected string $model = {model}::class;

protected string $title = 'DummyTitle';

{properties}
/**
* @return list<Page>
*/
Expand Down

0 comments on commit 5f4bcc5

Please sign in to comment.