Skip to content

Instantly share code, notes, and snippets.

@chrisblackwell
Created December 13, 2018 16:38
Show Gist options
  • Save chrisblackwell/ba9fc17fc5f455bae74642461f3b6777 to your computer and use it in GitHub Desktop.
Save chrisblackwell/ba9fc17fc5f455bae74642461f3b6777 to your computer and use it in GitHub Desktop.
Laravel make command
<?php
namespace App;
use Illuminate\Support\Str;
use Illuminate\Console\GeneratorCommand;
use Symfony\Component\Console\Input\InputOption;
class SomethingMakeCommand extends GeneratorCommand
{
protected $name = 'make:something';
protected $description = 'Create a new Something class';
protected $type = 'Something';
public function handle()
{
if (parent::handle() === false) {
if (! $this->option('force')) {
return;
}
}
}
protected function getStub()
{
return __DIR__.'/../../stubs/DummySomething.stub';
}
protected function getDefaultNamespace($rootNamespace)
{
if ($this->isCustomNamespace()) {
return $rootNamespace;
}
return $rootNamespace.'\Something';
}
protected function getOptions(): array
{
return [
['force', null, InputOption::VALUE_NONE, 'Create the class even if the view-model already exists'],
];
}
protected function isCustomNamespace(): bool
{
return Str::contains($this->argument('name'), '/');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment