2020_12_03_114353_add_auth_of_station.php 789 B

1234567891011121314151617181920212223242526272829303132333435363738
  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 AddAuthOfStation 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. foreach ($this->authNames as $name){
  20. if(!Authority::where('name',$name)->first())(new Authority(['name'=>$name,'alias_name'=>$name]))->save();
  21. }
  22. }
  23. /**
  24. * Reverse the migrations.
  25. *
  26. * @return void
  27. */
  28. public function down()
  29. {
  30. foreach ($this->authNames as $name){
  31. Authority::where('name',$name)->delete();
  32. }
  33. }
  34. }