2020_11_30_140958_create_stations_table.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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料箱监视器01= StationType::query()->firstOrCreate(['name'=>'料箱监视器01']);
  27. $station= Station::query()->firstOrCreate(['name'=>'U型线入货口01'
  28. ,'code'=>'BIN-OUT1'
  29. ,'station_type_id'=>$stationType['id']
  30. ,'parent_id'=>$station料箱监视器01['id']
  31. ]);
  32. $station['sequence']=1;
  33. $station['station_type_id']=$stationType['id'];
  34. $station->save();
  35. }
  36. /**
  37. * Reverse the migrations.
  38. *
  39. * @return void
  40. */
  41. public function down()
  42. {
  43. Schema::dropIfExists('stations');
  44. }
  45. }