2020_11_30_140958_create_stations_table.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. use App\Station;
  3. use App\StationType;
  4. use Illuminate\Database\Migrations\Migration;
  5. use Illuminate\Database\Schema\Blueprint;
  6. use Illuminate\Support\Facades\Schema;
  7. class CreateStationsTable extends Migration
  8. {
  9. /**
  10. * Run the migrations.
  11. *
  12. * @return void
  13. */
  14. public function up()
  15. {
  16. Schema::create('stations', function (Blueprint $table) {
  17. $table->id();
  18. $table->integer('parent_id')->index()->nullable();
  19. $table->string('name')->index()->nullable();
  20. $table->string('code')->unique()->nullable()->comment('机器编码');
  21. $table->integer('station_type_id')->index();
  22. $table->integer('sequence')->index()->nullable();
  23. $table->timestamps();
  24. });
  25. $stationType= StationType::query()->firstOrCreate(['name'=>'料箱出货口']);
  26. $station= Station::query()->firstOrCreate(['code'=>'BIN-OUT01','station_type_id'=>$stationType['id']]);
  27. $station['sequence']=1;
  28. $station['station_type_id']=$stationType['id'];
  29. $station->save();
  30. }
  31. /**
  32. * Reverse the migrations.
  33. *
  34. * @return void
  35. */
  36. public function down()
  37. {
  38. Schema::dropIfExists('stations');
  39. }
  40. }