Using stubs in commands
To use stubs in commands, use the GeneratesFiles
trait in your command.
use Javaabu\GeneratorHelpers\Concerns\GeneratesFiles;
use Illuminate\Console\Command;
class FactoryGenerateCommand extends Command
{
use GeneratesFiles;
...
Available Methods
The trait will add the following methods to your command.
getFilesystem()
: Returns the Laravel Filesystem instancegetRenderer()
: Returns aStubRenderer
instancegetFullFilePath(string $path, string $file_name)
: Returns the full file path with the file name appended to the path.getPath(string $default, string $path = '')
: Returns thedefault
path if nopath
given. Otherwise, returns the full absolute path relative to the project base path.appendContent(string $file_path, array $contents, string $stub = '')
: If the given file exists, appends the given contents to that file usingStubRenderer
appendMultipleContent
method. Otherwise, creates a new file at the given file path using the given stub and appends the content.putContent(string $file_path, string $content, bool $force = false)
: Creates a file at the given file path with the given content. Returns an error if file already exists, unless using theforce
option. When using theforce
option, the file is overwritten.alreadyExists(string $path)
: Checks if a given file already exists.makeDirectory(string $path)
: Creates a directory at the given path.