gpt4 book ai didi

php - 无法通过传递的输入深入扩展 Laravel Artisan Command

转载 作者:行者123 更新时间:2023-12-04 15:58:44 30 4
gpt4 key购买 nike

试图创建一个基本命令,然后扩展它。提供给扩展命令的输入不会使其沿树向下。

BaseApiClassBuilder.php

use Illuminate\Console\Command;

class BaseApiClassBuilder extends Command
{
// rest of class follows...
}

MakeApiCollection.php
class MakeApiCollection extends BaseApiClassBuilder
{

protected $signature = 'make:apicollection {name} {--namespace=}';

protected $description = 'Make an API Collection/Resource';

// guts of class...
}

我正在运行的控制台命令
artisan make:apicollection testApiCollection

收到控制台错误:

The command defined in "App\Console\Commands\BaseApiClassMaker" cannot have an empty name.



Can you extend Command classes in Laravel 类似的问题但那个有点过时,不太具体,也没有得到答复。

该错误仅在我扩展基本命令而不是“命令”时发生。

我已经确定在构造函数中没有调用验证,实际上很难弄清楚输入在哪里被验证,以及为什么它没有一路向下。

毫无疑问,我正在做一些愚蠢的事情,并且有一个简单的解决方案......但我找不到它!

我任何人都可以帮助我更好地理解这一点,非常感谢收到评论/答案/反馈。如果我完全以错误的方式处理这个问题,也请告诉我。我确实注意到我可以延长 GeneratorCommand相反,它有许多我需要的 helper ,但似乎并没有解决这个问题。

最佳答案

通过使父类抽象,您不需要定义 signature

<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;

abstract class BaseCommand extends Command
{
...
}

稍后在子类中设置 signature如所须
class ChildCommand extends BaseCommand
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'make:apicollection {specific-name} {--namespace=}';

关于php - 无法通过传递的输入深入扩展 Laravel Artisan Command,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55738140/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com