2019_11_22_094241_create_provinces_table.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. use Illuminate\Database\Migrations\Migration;
  3. use Illuminate\Database\Schema\Blueprint;
  4. use Illuminate\Support\Facades\Schema;
  5. use Illuminate\Support\Facades\DB;
  6. class CreateProvincesTable extends Migration
  7. {
  8. protected $provinces=[
  9. '陕西','甘肃','宁夏','青海','新疆','江苏','浙江','安徽','江西','福建','重庆','四川','云南',
  10. '贵州','西藏','黑龙江','吉林','辽宁','山东','北京','天津','广西','广东','河北','山西','内蒙古',
  11. '湖北','湖南','河南','海南','香港','澳门','台湾','上海'];
  12. /**
  13. * Run the migrations.
  14. *
  15. * @return void
  16. */
  17. public function up()
  18. {
  19. Schema::create('provinces', function (Blueprint $table) {
  20. $table->bigIncrements('id');
  21. $table->string('name',50)->unique()->comment('名称');
  22. $table->timestamps();
  23. });
  24. foreach ($this->provinces as $province){
  25. DB::insert(DB::raw("INSERT INTO provinces(name,created_at,updated_at) VALUES(?,?,?)"),[
  26. $province,date("Y-m-d"),date("Y-m-d")
  27. ]);
  28. }
  29. }
  30. /**
  31. * Reverse the migrations.
  32. *
  33. * @return void
  34. */
  35. public function down()
  36. {
  37. Schema::dropIfExists('provinces');
  38. }
  39. }