2020_10_20_134819_create_customers_table.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. * Run the migrations.
  17. *
  18. * @return void
  19. */
  20. public function up()
  21. {
  22. Schema::create('customers', function (Blueprint $table) {
  23. $table->id();
  24. $table->string('code')->unique()->comment('客户代码');
  25. $table->string('name')->comment('客户名称');
  26. $table->timestamp('created_at');
  27. });
  28. foreach ($this->authNames as $name){
  29. if(!Authority::query()->where('name',$name)->first())(new Authority(['name'=>$name,'alias_name'=>$name]))->save();
  30. }
  31. }
  32. /**
  33. * Reverse the migrations.
  34. *
  35. * @return void
  36. */
  37. public function down()
  38. {
  39. Schema::dropIfExists('customers');
  40. foreach ($this->authNames as $name){
  41. Authority::query()->where('name',$name)->delete();
  42. }
  43. }
  44. }