2019_11_22_094213_create_units_table.php 826 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. <?php
  2. use Illuminate\Database\Migrations\Migration;
  3. use Illuminate\Database\Schema\Blueprint;
  4. use Illuminate\Support\Facades\Schema;
  5. class CreateUnitsTable extends Migration
  6. {
  7. /**
  8. * Run the migrations.
  9. *
  10. * @return void
  11. */
  12. public function up()
  13. {
  14. Schema::create('units', function (Blueprint $table) {
  15. $table->bigIncrements('id');
  16. $table->timestamps();
  17. $table->string('name',50)->unique()->comment('名称');
  18. });
  19. $units=['kg','m³','T'];
  20. for ($i=0;$i<count($units);$i++){
  21. \App\Unit::create([
  22. 'name'=>$units[$i],
  23. ]);
  24. }
  25. }
  26. /**
  27. * Reverse the migrations.
  28. *
  29. * @return void
  30. */
  31. public function down()
  32. {
  33. Schema::dropIfExists('units');
  34. }
  35. }