<?php

use App\Authority;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class ChangeAuthoritiesTable extends Migration
{

    protected $authNames=[
       "退货管理-到付费用"
    ];
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::table('authorities',function (Blueprint $table){
            $table->enum('permission',['允许','禁止'])->after('alias_name')->default('允许')->comment('许可');
        });
        foreach ($this->authNames as $name){
            if(!Authority::where('name',$name)->first())(new Authority(['name'=>$name,'alias_name'=>$name,'permission'=>'禁止']))->save();
        }
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::table('authorities',function (Blueprint $table){
            $table->dropColumn('permission');
        });
        foreach ($this->authNames as $name){
            Authority::where('name',$name)->delete();
        }
    }
}
