chore: add command to generate actions
use `artisan make:action <name>` to generate final & readonly php class with execute method.
This commit is contained in:
parent
6419adb7d1
commit
30bc4a0cf3
32
backend/app/Console/Commands/MakeActionCommand.php
Normal file
32
backend/app/Console/Commands/MakeActionCommand.php
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Console\Commands;
|
||||||
|
|
||||||
|
use Illuminate\Console\GeneratorCommand;
|
||||||
|
|
||||||
|
class MakeActionCommand extends GeneratorCommand
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The name and signature of the console command.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $signature = 'make:action {name}';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The console command description.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $description = 'Create a new action class';
|
||||||
|
|
||||||
|
protected function getStub(): string
|
||||||
|
{
|
||||||
|
return base_path('stubs/action.stub');
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getDefaultNamespace($rootNamespace): string
|
||||||
|
{
|
||||||
|
return $rootNamespace.'\Actions';
|
||||||
|
}
|
||||||
|
}
|
||||||
14
backend/stubs/action.stub
Normal file
14
backend/stubs/action.stub
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace {{ namespace }};
|
||||||
|
|
||||||
|
final readonly class {{ class }}
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Execute the action.
|
||||||
|
*/
|
||||||
|
public function execute()
|
||||||
|
{
|
||||||
|
// Your logic here
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user