【问题标题】:Generate files using custom artisan make command Laravel使用自定义工匠 make 命令生成文件 Laravel
【发布时间】:2020-07-09 22:02:37
【问题描述】:

我正在尝试使用自定义 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 laravel-artisan


    【解决方案1】:

    删除handle 方法。它覆盖了GeneratorCommand 类的handle,这就是它什么都不做的原因。如果您想扩展handle 方法,请在语句之前或之后调用parent::handle()

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-09-19
      • 1970-01-01
      • 2015-07-04
      • 2021-08-11
      • 2014-08-30
      • 1970-01-01
      • 1970-01-01
      • 2014-09-07
      相关资源
      最近更新 更多