2019_11_22_094241_create_provinces_table.php 1.1 KB

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