Search code examples
laravelcustomizationlaravel-artisan

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?


Solution

  • 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.