<?php

namespace Database\Seeders;

use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\File;
use App\Models\User;

class EmailSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        //
        $json = File::get("database/MAA.json");
        $maa = json_decode($json);
        $email_json = File::get("database/MAA_email.json");
        $emails = json_decode($email_json);

        foreach ($maa as $key => $value) {

            $email = isset($emails->{$value->user_id}) ? ($emails->{$value->user_id}->email) : $value->user_id . " " . $value->name . "/maa";

            User::where('user_id',$value->user_id)
            ->update(['email' => $email]);
        }
    }
}
