简体   繁体   中英

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?

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM