Beispiel #1
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     // Models path defined in .env
     $model = $this->argument('model');
     $modelPath = env('MODELS');
     $s = file_get_contents('app/Console/Commands/stubs/Model.stub');
     $s = $this->replace($s, $model);
     $output = $modelPath . str_singular($model) . '.php';
     file_put_contents($output, $s);
     // {-c} Controller
     if ($this->option('c')) {
         $s = file_get_contents('app/Console/Commands/stubs/Controller.stub');
         $s = $this->replace($s, $model);
         $output = "app/Http/Controllers/" . str_plural($model) . 'Controller.php';
         file_put_contents($output, $s);
         $this->line($s);
     }
     // {-m} Migration
     if ($this->option('m')) {
         $s = file_get_contents('app/Console/Commands/stubs/Migration.stub');
         $s = $this->replace($s, $model);
         $output = "database/migrations/" . date('Y_m_d_his') . "_create_" . str_to_lower(str_plural($model)) . '_table.php';
         file_put_contents($output, $s);
         $this->line($s);
         // Create new table
         $this->call('migrate:refresh --seed');
     }
     // {-s} Seeder
     if ($this->option('s')) {
         $s = file_get_contents('app/Console/Commands/stubs/Seeder.stub');
         $s = $this->replace($s, $model);
         $output = "database/seeds/" . str_plural($model) . 'TableSeeder.php';
         file_put_contents($output, $s);
         // Add seeder to DatabaseSeeder
         $this->call('zulu:refactor-database-seeder');
     }
 }
 public static function setConstraint($name, $extras)
 {
     $name = str_to_lower($name);
     $possible_extras = array('unique', 'foreign_key', 'primary_key');
     if (!in_array(trim($name), $possible_extras)) {
         echo "Constraint not found in array of extras. Possible options " . implode(',', $possible_extras);
         return false;
     }
     if ($name == 'unique') {
         return 'ALTER TABLE TABLE_NAME ADD CONSTRAINT constr_ID UNIQUE (user_id, game_id, date, time)';
         return 'ADD CONSTRAINT `FK_myKey` FOREIGN KEY (`customer_id`) REFERENCES `customers` (`customer_id)';
         return 'ADD PRIMARY KEY (`id`);';
     }
 }