File "2019_08_12_073129_update_settings_add_envato_key.php"

Full Path: /home/isoftco/public_html/hrm/database/migrations/2019_08_12_073129_update_settings_add_envato_key.php
File size: 1.02 KB
MIME-type: text/x-php
Charset: utf-8

<?php

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

class UpdateSettingsAddEnvatoKey extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::table('settings', function (Blueprint $table) {
            $table->string('purchase_code', 100)->nullable();

        });

        $legalFile = storage_path() . '/legal';
        if (file_exists($legalFile)) {
            $legalFileInfo = File::get($legalFile);

            $legalFileInfo = explode('**', $legalFileInfo);
            $purchaseCode = $legalFileInfo[1];

            $setting = \App\Models\Setting::first();
            if ($setting) {
                $setting->purchase_code = $purchaseCode;
                $setting->save();
            }

        }
    }

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