0

I need to create a number of files in a specific format. So I planned to create a generate command by extending GeneratorCommand. I want to create view files and view-config files in application root directory.

The problem is, I did not find any official doc to do so. There are some article in the web, which suggests to use getDefaultNamespace method to set the path like the following. I was following the steps suggested at https://laravelpackage.com/06-artisan-commands.html#creating-a-generator-command. But I want to create files in root dir not into app dir. When i remove the $rootNamespace form the method it does not create files.

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

how can i create a command to generate files in specific directories in the application?

2
  • Does it work now? Commented May 5, 2021 at 9:19
  • @GordonFreeman not successful yet, checking the package you referred. Commented May 7, 2021 at 11:39

1 Answer 1

1

The class GeneratorCommand has a protected method rootNamespace. If I understand correctly, it returns the root ouf your application.

So you should be able to override the method getNamespace like so:

/**
 * Get the full namespace for a given class, without the class name.
 *
 * @param  string  $name
 * @return string
 */
protected function getNamespace($name)
{
    $rootNamespace = trim($this->rootNamespace(), '\\');
    return $this->getDefaultNamespace($rootNamespace);
}

NOTE
You can see a working example in one of my open source projects.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.