<?php

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

class CreateCustomerTagCustomerTable extends Migration
{
    protected $authorities = [
        "客户-客户标签",
        "客户-客户标签-查询",
        "客户-客户标签-录入",
        "客户-客户标签-编辑",
        "客户-客户标签-删除",
    ];
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('customer_tag_customer', function (Blueprint $table) {
            $table->bigInteger("customer_id");
            $table->bigInteger("customer_tag_id");
        });
        foreach ($this->authorities as $authority){
            \App\Authority::query()->firstOrCreate([
                "name"        =>  $authority,
                "alias_name"  =>  $authority,
            ]);
        }
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('customer_tag_customer');
        foreach ($this->authorities as $authority){
            \App\Authority::query()->where("name",$authority)->where("alias_name",$authority)->delete();
        }
    }
}
