mercredi 17 avril 2019

Unable to deeply extend Laravel Artisan Command with input passed down

Attempting to create a base command, and then extend it. Input provided to the extending command doesn't make it down the tree.

BaseApiClassBuilder.php

use Illuminate\Console\Command;

class BaseApiClassBuilder extends Command
{

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

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

    // rest of class follows...
}

MakeApiCollection.php

class MakeApiCollection extends BaseApiClassBuilder
{
    // guts of class...
}

Console Command I am running

artisan make:apicollection testApiCollection

Console Error Recieved:

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

Similar question to Can you extend Command classes in Laravel but that one is a bit out of date and less specific, and also unanswered.

The error only occurs when I extend my base command, instead of 'command'.

I've determined that the validation isn't called in the constructor, it's actually quite tricky to figure out where the input is being validated, and why it isn't making it all the way down.

No doubt I'm doing something goofy and there's an easy solution... but I can't find it!

I anyone can help me understand this better, comments/answers/feedback very gratefully received. If I'm approaching this completely the wrong way, let me know too. I did notice I could have extended GeneratorCommand instead which has many of the helpers I need, but doesn't seem to solve this problem.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire