Skip to content

Commit c0675de

Browse files
committed
feat: add MakeAction command to generate action classes
1 parent 833c180 commit c0675de

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
3+
namespace App\Console\Commands;
4+
5+
use Illuminate\Console\GeneratorCommand;
6+
7+
class MakeAction extends GeneratorCommand
8+
{
9+
/**
10+
* The name and signature of the console command.
11+
*
12+
* @var string
13+
*/
14+
protected $signature = 'make:action {name}';
15+
16+
/**
17+
* The console command description.
18+
*
19+
* @var string
20+
*/
21+
protected $description = 'Generates an action';
22+
23+
protected function getStub()
24+
{
25+
return __DIR__ . '/stubs/action.stub';
26+
}
27+
28+
protected function getDefaultNamespace($rootNamespace)
29+
{
30+
return $rootNamespace . '\Actions';
31+
}
32+
33+
protected function replaceClass($stub, $name)
34+
{
35+
return str_replace('{{ class }}', $this->argument("name"), parent::replaceClass($stub, $name));
36+
}
37+
38+
protected function promptForMissingArgumentsUsing()
39+
{
40+
return [
41+
"name" => [
42+
"What should the Action be named?",
43+
"E.g. CreatePost"
44+
]
45+
];
46+
}
47+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
namespace {{ namespace }};
4+
5+
class {{ class }}
6+
{
7+
public function handle()
8+
{
9+
//
10+
}
11+
}

0 commit comments

Comments
 (0)