<?php

use Illuminate\Database\Seeder;
use App\Models\ElementsDensity as ElementsDensityModel;

class ElementsDensityDataSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
    	ElementsDensityModel::truncate();
    	$elements = [
    		'copper',
    		'silver',
    		'gold',
    		'platinum'
    	];
        $start_date = '2019-01-01';
        $end_date = date('Y-m-d');

        while (strtotime($start_date) <= strtotime($end_date)) {
            echo "$start_date\n";
            foreach ($elements as $value) {
               $new_elements = new ElementsDensityModel;
               $new_elements->elements = $value;
               $new_elements->density = rand(10,50);
               $new_elements->created_at = $start_date;
               $new_elements->updated_at = $start_date;
               $new_elements->save();
           }
           $start_date = date ("Y-m-d", strtotime("+1 month", strtotime($start_date)));
       }
    }
}
