<?php

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

class UpdateResidentialComplexCustomerCount extends Migration
{
    public function up()
    {
        $residentialComplexes = App\ResidentialComplex::all();
        foreach ($residentialComplexes as $residentialComplex) {
//            $customerRatingCount = $residentialComplex->customerRating->count();
            $customerRatingCount = $residentialComplex->customerRating()->whereNull('deleted_at')
                ->where('enabled', 1)->get()->count();
            if ($customerRatingCount > 0) {
                $customerCountRand = rand(1, 10);
                $residentialComplex->customer_rating_count = $customerCountRand;
                $residentialComplex->update();
            }
        }
    }

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