<?php

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

class UpdateGeneralTable extends Migration
{
    /**
     * The name of the table.
     * 
     * @var string
     */
    protected $table_name = 'general';

    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::table($this->table_name, function (Blueprint $table) {

            if($this->hasColumn('general_title')) {
                $table->string('general_title')->nullable()->change();
            } else {
                $table->string('general_title')->nullable();
            }
            
            if($this->hasColumn('general_url')) {
                $table->string('general_url')->nullable()->change();
            } else {
                $table->string('general_url')->nullable();
            }

            if($this->hasColumn('general_content')) {
                $table->text('general_content')->nullable()->change();
            } else {
                $table->text('general_content')->nullable();
            }

            if($this->hasColumn('general_desc')) {
                $table->text('general_desc')->nullable()->change();
            } else {
                $table->text('general_desc')->nullable();
            }

        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        //
    }


    /**
     * Check if table has column.
     * 
     * @param string $column_name
     */
    public function hasColumn($column_name) {
        return Schema::hasColumn($this->table_name, $column_name);
    }
}
