<?php

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

class ChangeAuthOrderIndex extends Migration
{
    protected $changeNames=[
        ['订单管理-发运','订单管理-查询'],
    ];
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        //修改或没有则添加
        foreach ($this->changeNames as $namePack){
            $authority=Authority::where('name',$namePack[0])->orWhere('name',$namePack[1])->first();
            if(!$authority){
                (new Authority(['name'=>$namePack[1],'alias_name'=>$namePack[1]]))->save();
            }elseif($authority['name']==$namePack[0]){
                $authority['name']=$namePack[1];
                $authority['alias_name']=$namePack[1];
                $authority->save();
            }
        }
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        //改回旧的
        foreach ($this->changeNames as $namePack){
            $authority=Authority::where('name',$namePack[1])->first();
            $authority['name']=$namePack[0];
            $authority->save();
        }
    }
}
