| 123456789101112131415161718192021222324252627282930313233343536373839 |
- <?php
- use Illuminate\Database\Migrations\Migration;
- use Illuminate\Database\Schema\Blueprint;
- use Illuminate\Support\Facades\Schema;
- use Illuminate\Support\Facades\DB;
- class CreateUnitsTable extends Migration
- {
- protected $units = ['kg','m³','T','件', '托',"箱",'单',"日","月","m²","年"];
- /**
- * Run the migrations.
- *
- * @return void
- */
- public function up()
- {
- Schema::create('units', function (Blueprint $table) {
- $table->bigIncrements('id');
- $table->timestamps();
- $table->string('name',50)->unique()->comment('名称');
- });
- for ($i=0;$i<count($this->units);$i++){
- DB::insert(DB::raw("INSERT INTO units(name,created_at,updated_at) VALUES(?,?,?)"),[
- $this->units[$i],date("Y-m-d"),date("Y-m-d")
- ]);
- }
- }
- /**
- * Reverse the migrations.
- *
- * @return void
- */
- public function down()
- {
- Schema::dropIfExists('units');
- }
- }
|