2020_10_20_134819_create_customers_table.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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 CreateCustomersTable extends Migration
  7. {
  8. protected $authNames=[
  9. '客户管理',
  10. '客户管理-项目',
  11. '客户管理-项目-报表',
  12. '客户管理-项目-查询',
  13. '客户管理-项目-录入',
  14. '客户管理-项目-面积',
  15. ];
  16. /**
  17. * Run the migrations.
  18. *
  19. * @return void
  20. */
  21. public function up()
  22. {
  23. Schema::create('customers', function (Blueprint $table) {
  24. $table->id();
  25. $table->string('code')->unique()->comment('客户代码');
  26. $table->string('name')->comment('客户名称');
  27. $table->timestamp('created_at');
  28. });
  29. foreach ($this->authNames as $name){
  30. if(!Authority::query()->where('name',$name)->first())(new Authority(['name'=>$name,'alias_name'=>$name]))->save();
  31. }
  32. }
  33. /**
  34. * Reverse the migrations.
  35. *
  36. * @return void
  37. */
  38. public function down()
  39. {
  40. Schema::dropIfExists('customers');
  41. foreach ($this->authNames as $name){
  42. Authority::query()->where('name',$name)->delete();
  43. }
  44. }
  45. }