<?php

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

class AddAuthorityToLevel3Page extends Migration
{
    protected $authorityNames = [
        '客户管理-财务',
        '客户管理-客户',
        '客户管理-相关设置',
        '称重管理-快递',
        '人事管理-相关设置',
        '二次加工管理-相关设置',
        '入库管理-Excel下载',
        '入库管理-手持入口',
    ];

    public function up()
    {
        foreach ($this->authorityNames as $authorityName) {
            if(!Authority::query()->where('name',$authorityName)->exists())
                Authority::query()->create(['name' => $authorityName,'alias_name' => $authorityName]);
        }

    }
    public function down()
    {
        foreach ($this->authorityNames as $authorityName) {
            $authority  = Authority::query()->where('name' ,$authorityName )->first();
            $authority->delete();
        }
    }
}
