MakeModelCommand.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. return parent::getOptions()[]=
  36. ['service', 'sv', InputOption::VALUE_NONE, 'Create a new service file'];
  37. }
  38. }