使用定制的工匠制作命令Laravel生成文件

问题描述 投票:0回答:1

我正在尝试使用自定义artisan make命令生成类文件。我的命令显示在artisan make下,但我无法生成文件我做了什么

1。使用php artisan make:command CreateActionClass and implement GeneratorCommand

<?php

namespace App\Console\Commands;
use Illuminate\Console\GeneratorCommand;
use Symfony\Component\Console\Input\InputArgument;

class CreateActionClass extends GeneratorCommand
{  
protected $signature = 'make:action {name}';

protected $description = 'Create New Action Single Responsibility';

protected $type = 'Action';

public function handle()
{
    //
}

protected function getStub()
{       
    return  app_path().'/Console/Stubs/MakeActionStub.stub';
}

protected function getDefaultNamespace($rootNamespace)
{
    return $rootNamespace.'\Actions';
}
    protected function getArguments()
{
    return [
        ['name', InputArgument::REQUIRED, 'The name of the contract.'],
    ];
}}

2。生成.stub文件/Console/Stubs/MakeActionStub.stub

<?php
namespace DummyNamespace;
class DummyAction
{

}

请帮助

laravel artisan
1个回答
0
投票
删除handle方法。它覆盖了GeneratorCommand类的handle,因此它什么也不做。如果您想扩展handle方法,请在语句之前或之后调用parent::handle()
© www.soinside.com 2019 - 2024. All rights reserved.