123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- <?php
- namespace App\Console\Commands;
- use Illuminate\Console\Command;
- use Illuminate\Support\Collection;
- use Prettus\Repository\Generators\ControllerGenerator;
- use Prettus\Repository\Generators\FileAlreadyExistsException;
- use Symfony\Component\Console\Input\InputArgument;
- use Symfony\Component\Console\Input\InputOption;
- class ControllerCommand extends Command
- {
-
- protected $name = 'make:resource';
-
- protected $description = 'Create a new RESTful controller.';
-
- protected $type = 'Controller';
-
- public function __construct()
- {
- $this->name = ((float)app()->version() >= 5.5 ? 'make:rest-controller' : 'make:resource');
- parent::__construct();
- }
-
- public function handle()
- {
- $this->laravel->call([$this, 'fire'], func_get_args());
- }
-
- public function fire()
- {
- try {
-
- $this->call('make:request', [
- 'name' => $this->argument('name') . 'CreateRequest'
- ]);
-
- $this->call('make:request', [
- 'name' => $this->argument('name') . 'UpdateRequest'
- ]);
- (new ControllerGenerator([
- 'name' => $this->argument('name'),
- 'force' => $this->option('force'),
- ]))->run();
- $this->info($this->type . ' created successfully.');
- } catch (FileAlreadyExistsException $e) {
- $this->error($this->type . ' already exists!');
- return false;
- }
- }
-
- public function getArguments()
- {
- return [
- [
- 'name',
- InputArgument::REQUIRED,
- 'The name of model for which the controller is being generated.',
- null
- ],
- ];
- }
-
- public function getOptions()
- {
- return [
- [
- 'force',
- 'f',
- InputOption::VALUE_NONE,
- 'Force the creation if file already exists.',
- null
- ],
- ];
- }
- }
|