MakeModelCommand.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. namespace App\Console\Commands;
  3. use Illuminate\Support\Str;
  4. use Symfony\Component\Console\Input\InputOption;
  5. class MakeModelCommand extends \Illuminate\Foundation\Console\ModelMakeCommand
  6. {
  7. protected function getStub()
  8. {
  9. if ($this->option('pivot')) {
  10. return parent::getStub();
  11. }
  12. return __DIR__ . '/stubs/model.stub';
  13. }
  14. public function handle()
  15. {
  16. if (parent::handle() === false && ! $this->option('force')) {
  17. return false;
  18. }
  19. if ($this->option('all')) {
  20. $this->input->setOption('service', true);
  21. }
  22. if ($this->option('service')) {
  23. $this->createService();
  24. }
  25. }
  26. public function createService()
  27. {
  28. $modelName = Str::studly(class_basename($this->argument('name')));
  29. $this->call('make:service', [
  30. 'name' => "{$modelName}Service",
  31. ]);
  32. }
  33. protected function getOptions(): array
  34. {
  35. $options= parent::getOptions();
  36. $options[]=['service', 'sv', InputOption::VALUE_NONE, 'Create a new service file'];
  37. return $options;
  38. }
  39. }