コード例 #1
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     //borrramos generaciones previas
     File::deleteDirectory(app_path('modelos_generados'));
     //creamos el directorio en app..
     File::makeDirectory(app_path('modelos_generados'), 777);
     $tablas = SchemaHelper\Table::getTablesCurrentDatabase();
     $this->info("Buscando tablas..");
     foreach ($tablas as $tabla) {
         $this->info("Generando Modelo de la tabla: " . $tabla->table_name);
         //class name
         $class_name = ucfirst(camel_case(str_singular_spanish($tabla->table_name)));
         $baseString = File::get(app_path('models/Schema/Template.txt'));
         //replace class name..
         $baseString = str_replace('@class_name@', $class_name, $baseString);
         //replace table name..
         $baseString = str_replace('@table_name@', $tabla->table_name, $baseString);
         //replace pretty name..
         $baseString = str_replace('@pretty_name@', $tabla->table_name, $baseString);
         //find columns.
         $columns = $tabla->columns()->whereNotIn('column_name', static::$common_hidden)->get();
         //generate fillable
         $baseString = str_replace('@fillable@', $this->generarFillable($columns), $baseString);
         //generate pretty fields string.
         $baseString = str_replace('@pretty_fields@', $this->generarPrettyFields($columns), $baseString);
         //generate rules..
         $baseString = str_replace('@rules@', $this->genenarRules($columns), $baseString);
         //generate belongs to..
         $baseString = str_replace('@belongs_to@', $this->generarBelongsTo($columns), $baseString);
         File::put(app_path('modelos_generados/' . $class_name . '.php'), $baseString);
     }
     $this->info("Generación terminada.");
 }
コード例 #2
0
 public function getModelName()
 {
     if (is_null($this->modelName)) {
         $className = class_basename(get_class($this));
         $className = str_replace('Controller', '', $className);
         $className = str_singular_spanish($className);
         $this->modelName = ucfirst($className);
     }
     return $this->modelName;
 }