<?php

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

class AddAuthorritiesToMaterialsOwnerMaterialSuppliersConfigurations extends Migration
{
    private $names = [
        '耗材类型', '耗材类型-编辑','耗材类型-删除',
        '项目耗材', '项目耗材-编辑','项目耗材-删除','项目耗材-文件上传',
        '供应商', '供应商-编辑','供应商-删除',
        '系统配置','系统配置-编辑','系统配置-删除',
    ];


    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        foreach ($this->names as $name) {
            if(!Authority::query()->where('name',$name)->exists())
                Authority::query()->create(['name'=>$name,'alias_name'=>$name]);
        }
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Authority::query()->whereIn('name',$this->names)->delete();
    }
}
