<?php

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

class AddColumnArticleTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::table('articles', function (Blueprint $table){
            $table->integer('vertical')->nullable();
            $table->text('file_path2')->nullable();
            $table->text('file_type2')->nullable();
        });

        $photos = \App\Models\RelationArticlePhoto::whereNotNull('file_path2')->get();
        foreach ($photos as $photo){
            \App\Models\Article::where('building_id', $photo->article_id)->update([
                'vertical' => $photo->vertical,
                'file_path2' => $photo->file_path2,
                'file_type2' => $photo->file_type2
            ]);
        }

    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::table('articles', function (Blueprint $table){
            $table->dropColumn('vertical');
            $table->dropColumn('file_path2');
            $table->dropColumn('file_type2');
        });
    }
}
