diff src/Generator/Generator.php @ 5:b0b2e79ad8e6

Not exatly sure what was changed but commiting to it :)
author luka
date Thu, 12 Oct 2023 19:41:04 -0400
parents 6468684362c2
children 769a17898cc0
line wrap: on
line diff
--- a/src/Generator/Generator.php	Tue Jun 27 20:16:55 2023 -0400
+++ b/src/Generator/Generator.php	Thu Oct 12 19:41:04 2023 -0400
@@ -11,7 +11,6 @@
 use Illuminate\Support\Str;
 
 use Wizzard\MagicForger\Generator\BaseGenerator;
-use Wizzard\MagicForger\Replacer;
 
 #[AsCommand(name: 'mf')]
 class Generator extends BaseGenerator
@@ -44,12 +43,17 @@
             return false;
         }
 
+				$this->setCurrentTable($this->getTableInput());
+				dd($this->getCurrentTable()->getForeignKeys());
+
         if ($this->option('all')) {
             /* $this->input->setOption('factory', true); */
             /* $this->input->setOption('seed', true); */
             /* $this->input->setOption('migration', true); */
             $this->input->setOption('controller', true);
-            /* $this->input->setOption('model', true); */
+            $this->input->setOption('model', true);
+            $this->input->setOption('request', true);
+            $this->input->setOption('route', true);
         }
 
         /* if ($this->option('factory')) { */
@@ -68,9 +72,17 @@
             $this->createController();
         }
 
-        /* if ($this->option('model')) { */
-        /*     $this->createModel(); */
-        /* } */
+        if ($this->option('model')) {
+            $this->createModel();
+        }
+
+        if ($this->option('request')) {
+            $this->createRequest();
+        }
+
+        if ($this->option('route')) {
+            $this->createRoute();
+        }
 
     }
 
@@ -81,10 +93,13 @@
      */
     protected function getOptions()
     {
-        return [
+        return array_merge(parent::getOptions(), [
             ['all', 'a', InputOption::VALUE_NONE, 'Generate a migration, seeder, factory, policy, resource controller, and form request classes for the table.'],
             ['controller', 'c', InputOption::VALUE_NONE, 'Generate a controller class for the table.'],
-        ];
+            ['model', 'm', InputOption::VALUE_NONE, 'Generate a model class for the table.'],
+            ['request', 'r', InputOption::VALUE_NONE, 'Generate base request classes for the table.'],
+            ['route', 'w', InputOption::VALUE_NONE, 'Generate base routes classes for the table.'],
+        ]);
     }
 
     /**
@@ -102,6 +117,21 @@
 
     protected function createController()
     {
-        $this->call('mf:controller', ['table' => $this->getTableInput()]);
+        $this->call('mf:controller', ['table' => $this->getTableInput(), '--fresh' => $this->option('fresh')]);
+    }
+
+    protected function createModel()
+    {
+        $this->call('mf:model', ['table' => $this->getTableInput(), '--fresh' => $this->option('fresh')]);
+    }
+
+    protected function createRequest()
+    {
+        $this->call('mf:request', ['table' => $this->getTableInput(), '--fresh' => $this->option('fresh'), '--all' => true]);
+    }
+
+    protected function createRoute()
+    {
+        $this->call('mf:route', ['table' => $this->getTableInput(), '--fresh' => $this->option('fresh')]);
     }
 }