2020_06_12_093011_change_authorities_table.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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 ChangeAuthoritiesTable extends Migration
  7. {
  8. protected $authNames=[
  9. "退货管理-到付费用"
  10. ];
  11. /**
  12. * Run the migrations.
  13. *
  14. * @return void
  15. */
  16. public function up()
  17. {
  18. Schema::table('authorities',function (Blueprint $table){
  19. $table->enum('permission',['允许','禁止'])->after('alias_name')->default('允许')->comment('许可');
  20. });
  21. foreach ($this->authNames as $name){
  22. if(!Authority::where('name',$name)->first())(new Authority(['name'=>$name,'alias_name'=>$name,'permission'=>'禁止']))->save();
  23. }
  24. }
  25. /**
  26. * Reverse the migrations.
  27. *
  28. * @return void
  29. */
  30. public function down()
  31. {
  32. Schema::table('authorities',function (Blueprint $table){
  33. $table->dropColumn('permission');
  34. });
  35. foreach ($this->authNames as $name){
  36. Authority::where('name',$name)->delete();
  37. }
  38. }
  39. }