2020_06_16_171741_create_upload_files_table.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. use App\Authority;
  3. use Illuminate\Database\Migrations\Migration;
  4. use Illuminate\Database\Schema\Blueprint;
  5. use Illuminate\Support\Facades\Schema;
  6. class CreateUploadFilesTable extends Migration
  7. {
  8. protected $authNames=[
  9. "运输管理-图片上传",
  10. "运输管理-图片删除"
  11. ];
  12. /**
  13. * Run the migrations.
  14. *
  15. * @return void
  16. */
  17. public function up()
  18. {
  19. Schema::create('upload_files', function (Blueprint $table) {
  20. $table->string('table_name')->comment('表名');
  21. $table->string('table_id')->comment('表ID');
  22. $table->string('url')->unique()->comment('路径');
  23. $table->string('type')->nullable()->comment('类型');
  24. $table->timestamps();
  25. });
  26. foreach ($this->authNames as $name){
  27. if(!Authority::where('name',$name)->first())(new Authority(['name'=>$name,'alias_name'=>$name]))->save();
  28. }
  29. }
  30. /**
  31. * Reverse the migrations.
  32. *
  33. * @return void
  34. */
  35. public function down()
  36. {
  37. Schema::dropIfExists('upload_files');
  38. foreach ($this->authNames as $name){
  39. Authority::where('name',$name)->delete();
  40. }
  41. }
  42. }