Ejemplo n.º 1
0
 /**
  * Convert CSV to database table.
  *
  * @param   string  $table
  * @param   boolean  $table_already_exists
  * @param   boolean  $clear_existing_records
  * @return  void
  */
 public function to_database($table = null, $table_already_exists = false, $clear_existing_records = false)
 {
     // if no pre-existing table defined...
     if (!$table_already_exists) {
         $t = new \Table($table);
         $t->create();
         foreach ($this->columns as $column) {
             // create column; default length is 200
             $t->string($column);
         }
         \Schema::execute($t);
     } else {
         // if clear existing records...
         \DB::query(sprintf("TRUNCATE TABLE `%s`", $table));
     }
     // foreach row...
     foreach ($this->rows as $value) {
         // add to table
         \DB::table($table)->insert($value);
     }
 }