Mercurial > packages > magicforger
comparison src/Generator/ControllerGenerator.php @ 1:ca36acd2bef2
Have a base going, there is definitly a lot wrong with some of the files and the general structure but overall, it's a starting point
| author | luka |
|---|---|
| date | Sat, 24 Jun 2023 01:08:01 -0400 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 0:329123c41eaf | 1:ca36acd2bef2 |
|---|---|
| 1 <?php | |
| 2 namespace Magicforger\Generator; | |
| 3 | |
| 4 use Illuminate\Console\GeneratorCommand; | |
| 5 use Symfony\Component\Console\Input\InputOption; | |
| 6 | |
| 7 class ControllerGenerator extends GeneratorCommand | |
| 8 { | |
| 9 /** | |
| 10 * The console command name. | |
| 11 * | |
| 12 * @var string | |
| 13 */ | |
| 14 protected $name = 'make:table'; | |
| 15 | |
| 16 /** | |
| 17 * The console command description. | |
| 18 * | |
| 19 * @var string | |
| 20 */ | |
| 21 protected $description = 'Create a new controller and views for a table.'; | |
| 22 | |
| 23 /** | |
| 24 * The type of class being generated. | |
| 25 * | |
| 26 * @var string | |
| 27 */ | |
| 28 protected $type = 'Table Controller and Views'; | |
| 29 | |
| 30 /** | |
| 31 * Get the stub file for the generator. | |
| 32 * | |
| 33 * @return string | |
| 34 */ | |
| 35 protected function getStub() | |
| 36 { | |
| 37 // Use your own controller and views stubs here | |
| 38 return __DIR__ . '/stubs/table.stub'; | |
| 39 } | |
| 40 | |
| 41 /** | |
| 42 * Execute the console command. | |
| 43 * | |
| 44 * @return void | |
| 45 */ | |
| 46 public function handle() | |
| 47 { | |
| 48 parent::handle(); | |
| 49 | |
| 50 $tableName = $this->option('table'); | |
| 51 | |
| 52 // Create views directory | |
| 53 /* $directory = resource_path('views/' . strtolower($tableName)); */ | |
| 54 /* mkdir($directory, 0755, true); */ | |
| 55 | |
| 56 /* // Create index view */ | |
| 57 /* $indexViewPath = $directory . '/index.blade.php'; */ | |
| 58 /* file_put_contents($indexViewPath, ''); */ | |
| 59 | |
| 60 /* // Create create view */ | |
| 61 /* $createViewPath = $directory . '/create.blade.php'; */ | |
| 62 /* file_put_contents($createViewPath, ''); */ | |
| 63 | |
| 64 /* // Create edit view */ | |
| 65 /* $editViewPath = $directory . '/edit.blade.php'; */ | |
| 66 /* file_put_contents($editViewPath, ''); */ | |
| 67 | |
| 68 // Success message | |
| 69 $this->info('Table '. $tableName . ' controller and views created successfully.'); | |
| 70 } | |
| 71 | |
| 72 /** | |
| 73 * Get the console command options. | |
| 74 * | |
| 75 * @return array | |
| 76 */ | |
| 77 protected function getOptions() | |
| 78 { | |
| 79 return [ | |
| 80 ['table', null, InputOption::VALUE_REQUIRED, 'The name of the table.'] | |
| 81 ]; | |
| 82 } | |
| 83 } | |
| 84 |
