LaravelPackage.com icon indicating copy to clipboard operation
LaravelPackage.com copied to clipboard

Generator Commands

Open nasirkhan opened this issue 4 years ago • 3 comments

The site is awesome. Thank you for building this.

I was following the Artisan Commands page to build a Generator Command.

Can you please elaborate the generator section? I did not find any reference in the Laravel official doc as well.

I need to create a command, which will create a directory with a number of classes and other config files there. How can I pass values to a Stub? how to set a custom namespace ?

nasirkhan avatar Apr 13 '21 14:04 nasirkhan

Hi @nasirkhan

There are some blog posts to learn more about Laravel's Generator Command class if you'd need more clarification on that topic.

  • https://www.ystash.com/blog/create-a-generator-make-command-in-laravel/
  • https://techsemicolon.github.io/blog/2019/01/11/laravel-make-custom-class-using-console-command/

It is definitely possible to create a directory and a number of classes / config files using a generator command. You can take a look at Laravel's own make commands to figure out how they do it.

Take the make:component command for example: https://github.com/laravel/framework/blob/277c2fbd0cebd2cb194807654d870f4040e288c0/src/Illuminate/Foundation/Console/ComponentMakeCommand.php

Or perhaps one of the solutions provided in this StackOverflow thread: https://stackoverflow.com/questions/60170982/generate-multiple-files-with-laravel-command

Jhnbrn90 avatar Apr 19 '21 19:04 Jhnbrn90

thank you for the reference articles.

nasirkhan avatar Apr 30 '21 15:04 nasirkhan

thank you for sharing the links.

unfortunately I did not find the answer i was looking for. I need to create a directory outside App directory. Like generate View and some class files. I found the following to set the namespace, but it does not work if i remove the $rootNamespace.

protected function getDefaultNamespace($rootNamespace)
{
    return $rootNamespace.'\Actions';
}

I can create directory and files directly using php code, but i was looking for the laravel-way to do so. can you help me here?

nasirkhan avatar May 01 '21 18:05 nasirkhan