<?php

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

class AddColumnDeletedAtTableRegion extends Migration
{
    protected $name = [
        "地域",
        "地域-查询",
        "地域-录入",
        "地域-编辑",
        "地域-删除",
    ];
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::table('regions', function (Blueprint $table) {
            $table->softDeletes();
            $table->index("type");
        });

        foreach ($this->name as $name){
            \App\Authority::query()->firstOrCreate([
                "name"=>$name,
                "alias_name"=>$name
            ]);
        }
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::table('regions', function (Blueprint $table) {
            $table->dropSoftDeletes();
            $table->dropIndex(["type"]);
        });
        foreach ($this->name as $name){
            \App\Authority::query()->where("name",$name)->delete();
        }
    }
}
