Andrey Voskresenskiy
Andrey Voskresenskiy

Reputation: 35

Custom Laravel Artisan Make Controller command

I want to put my controller generated by the artisan command to a custom directory. I made own command

php artisan make:command ApiControllerMake

and extended it

class ApiControllerMake extends ControllerMakeCommand

then I removed everything from there and overridden method

protected function getDefaultNamespace($rootNamespace)
    {
        return $rootNamespace.'\Http\AppAPI\Controllers';
    }

It's working OK. Then I overridden

protected $signature = 'make:api-controller';

and after run

php artisan make:api-controller MyNewController

I got error

No arguments expected for "make:api-controller" command, got "MyNewController".

What is the problem?

Upvotes: 1

Views: 1368

Answers (1)

Ion
Ion

Reputation: 371

Take a look at the ControllerMakeCommand, they use

protected $name = 'make:controller';

You probably have this:

protected $signature = 'make:api-controller';

So in your new class, replace $signature with $name.

Upvotes: 1

Related Questions