| 123456789101112131415161718192021222324252627282930313233343536373839404142 |
- <?php
- use Illuminate\Database\Migrations\Migration;
- use Illuminate\Database\Schema\Blueprint;
- use Illuminate\Support\Facades\Schema;
- use Illuminate\Support\Facades\DB;
- class CreateProvincesTable extends Migration
- {
- protected $provinces=[
- '陕西','甘肃','宁夏','青海','新疆','江苏','浙江','安徽','江西','福建','重庆','四川','云南',
- '贵州','西藏','黑龙江','吉林','辽宁','山东','北京','天津','广西','广东','河北','山西','内蒙古',
- '湖北','湖南','河南','海南','香港','澳门','台湾','上海'];
- /**
- * Run the migrations.
- *
- * @return void
- */
- public function up()
- {
- Schema::create('provinces', function (Blueprint $table) {
- $table->bigIncrements('id');
- $table->string('name',50)->unique()->comment('名称');
- $table->timestamps();
- });
- foreach ($this->provinces as $province){
- DB::insert(DB::raw("INSERT INTO provinces(name,created_at,updated_at) VALUES(?,?,?)"),[
- $province,date("Y-m-d"),date("Y-m-d")
- ]);
- }
- }
- /**
- * Reverse the migrations.
- *
- * @return void
- */
- public function down()
- {
- Schema::dropIfExists('provinces');
- }
- }
|