<?php

namespace Database\Seeders;

use Illuminate\Database\Seeder;
use App\Models\Config;
use App\Models\Azienda;

class ConfigSeeder extends Seeder
{
  /**
  * Run the database seeds.
  *
  * @return void
  */
  public function run()
  {
    // Configurazione
    foreach(Azienda::all() as $azienda){
      foreach(Config::getConfig() as $key => $group){
        $order = 1;
        foreach($group as $key2 => $c){
          $config = Config::where([['key', $c['key']], ['azienda_id', $azienda->id]])->first();
          if($config == null){
            $config = new Config;
            $config->fill($c);
            $config->azienda_id = $azienda->id;
            $config->order = $order;
            $config->group = $key;
            $config->save();
            $order++;
          }
        }
      }
    }
  }
}
