<?php

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

class UpdatePriceData extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        $prices = \App\Price::all();
        $sortPrice = $prices->sortBy('residential_complex_id');
        foreach ($sortPrice as $price) {
            $explodePrice = explode('-', $price->price_per_squera_meter_copy);
//            dump($price->price_per_squera_meter_copy);
//            dump($price->residential_complex_id);
//            dump($price->section_id);
            if (count($explodePrice) >= 2) {
//                dump('2');
                $min = str_replace(' ', '', trim($explodePrice[0]));
                $max = str_replace(' ', '', trim($explodePrice[1]));
//                dump($min);
//                dump($max);
                $price->price_per_squera_meter = $min;
                $price->price_per_squera_meter_max = $max;
                dump($price);
            } else {
                $min = str_replace(' ', '', $price->price_per_squera_meter_copy);
                $price->price_per_squera_meter = $min;
//                dump($price);
            }

            $price->update();
        }

//        Schema::table('prices', function (Blueprint $table) {
//            if (Schema::hasColumn('prices', 'price_per_squera_meter_copy')) {
//                $table->dropColumn('price_per_squera_meter_copy');
//            }
//        });
    }

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