<?php

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

class AddCustomerPhoneAddress extends Migration
{
    protected $authorities = [
        "客户-客户状态",
        "客户-客户状态-查询",
        "客户-客户状态-录入",
        "客户-客户状态-编辑",
        "客户-客户状态-删除",
    ];
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::table('customers', function (Blueprint $table) {
            $table->string('invoice_address')->nullable()->comment('发票地址');
            $table->string('contact_man')->index()->nullable()->comment('联系人');
            $table->string('phone')->nullable()->comment('联系电话');
            $table->string('remark')->nullable()->comment('公司备注');
        });
        foreach ($this->authorities as $authority){
            \App\Authority::query()->firstOrCreate([
                "name"        =>  $authority,
                "alias_name"  =>  $authority,
            ]);
        }
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::table('customers',function (Blueprint $table){
            $table->dropColumn('invoice_address');
            $table->dropColumn('contact_man');
            $table->dropColumn('phone');
            $table->dropColumn('remark');
        });
        foreach ($this->authorities as $authority){
            \App\Authority::query()->where("name",$authority)->where("alias_name",$authority)->delete();
        }
    }
}
