/**
  * Execute the console command.
  *
  * @return void
  */
 public function fire()
 {
     // Scaffolding should always begin with the singular
     // form of the now.
     $this->model = Pluralizer::singular($this->argument('name'));
     $this->fields = $this->option('fields');
     if (is_null($this->fields)) {
         throw new MissingFieldsException('You must specify the fields option.');
     }
     // We're going to need access to these values
     // within future commands. I'll save them
     // to temporary files to allow for that.
     $this->cache->fields($this->fields);
     $this->cache->modelName($this->model);
     $this->generateModel();
     $this->generateController();
     $this->generateViews();
     $this->generateMigration();
     $this->generateSeed();
     if (get_called_class() === 'Way\\Generators\\Commands\\ScaffoldGeneratorCommand') {
         $this->generateTest();
     }
     $this->generator->updateRoutesFile($this->model);
     $this->info('Updated ' . app_path() . '/routes.php');
     // We're all finished, so we
     // can delete the cache.
     $this->cache->destroyAll();
 }
 protected function getPath()
 {
     $layout = $this->cache->getValue('layout');
     if (empty($layout)) {
         return parent::getPath();
     } else {
         return str_replace('scaffold', $layout, parent::getPath());
     }
 }
 /**
  * Get the path to the file that should be generated.
  *
  * @return string
  */
 protected function getPath()
 {
     $namespace = $this->cache->getValue('namespace');
     if (empty($namespace)) {
         return $this->option('path') . '/' . ucwords($this->argument('name')) . '.php';
     } else {
         return $this->option('path') . '/' . ucwords($namespace) . '/' . ucwords($this->argument('name')) . '.php';
     }
 }
 /**
  * Call generate:views
  *
  * @return void
  */
 protected function generateLocales()
 {
     $localesDir = app_path() . '/lang';
     $fields = $this->cache->getFields();
     $model = $this->cache->getModelName();
     $models = Pluralizer::plural($model);
     $Models = ucwords($models);
     $Model = Pluralizer::singular($Models);
     foreach ($this->locales as $locale) {
         $localeDir = empty($this->namespace) ? $localesDir . '/' . $locale : $localesDir . '/' . $locale . '/' . $this->namespace;
         $this->generator->folders(array($localeDir));
         $utils = '';
         $source = '';
         if ($this->generator->file->exists(__DIR__ . "/../Generators/templates/lang/{$locale}/model.txt")) {
             $utils = $this->generator->file->get(__DIR__ . "/../Generators/templates/lang/{$locale}/utils.txt");
             $source = $this->generator->file->get(__DIR__ . "/../Generators/templates/lang/{$locale}/model.txt");
         } else {
             $utils = $this->generator->file->get(__DIR__ . "/../Generators/templates/lang/en/utils.txt");
             $source = $this->generator->file->get(__DIR__ . "/../Generators/templates/lang/en/model.txt");
         }
         $modelFields = '';
         foreach (array_keys($fields) as $field) {
             $modelFields .= "  '{$field}' => '" . ucwords($field) . "',\n";
         }
         foreach (array('model', 'models', 'Models', 'Model', 'modelFields') as $var) {
             $source = str_replace('{{' . $var . '}}', ${$var}, $source);
         }
         if (!$this->generator->file->exists($localesDir . '/' . $locale . "/utils.php")) {
             $this->generator->file->put($localesDir . '/' . $locale . "/utils.php", $utils);
         }
         $this->generator->file->put($localeDir . "/{$models}.php", $source);
     }
 }