<?php

namespace Database\Seeders;

use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;
use App\Models\Message;
use App\Models\MessageComment;
use App\Models\User;
use File;

class MessageSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        //
        //$message = \App\Models\Message::factory(20)->create();
        Message::truncate();
        MessageComment::truncate();

        $json = File::get("database/message.json");
        $countries = json_decode($json);

        foreach ($countries as $key => $value) {
            Message::create([
                'title' => $value->title,
                'content' => $value->content,
                'author_id' => User::all()->random()->id,
                'preview' =>$value->preview,
                'tag' => $value->tag,
                'thumbnail' => $value->thumbnail,
                'created_at' => $value->time,
            ]);
        }
        MessageComment::factory(rand(10,11))->create();
    }
}
