/** * Create a new database table schema. * * @param string $table * @param Closure $callback * @return void */ public static function create($table, $callback) { $table = new Schema\Table($table); // To indicate that the table is new and needs to be created, we'll run // the "create" command on the table instance. This tells schema it is // not simply a column modification operation. $table->create(); call_user_func($callback, $table); return static::execute($table); }
/** * 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); } }
public static function create($table, $callback) { $table = new Schema\Table($table); $table->create(); call_user_func($callback, $table); return static::execute($table); }