<?php

use App\Category;
use App\User;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Str;

class ArticlesSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */


    public function run()
    {
        $user = User::first();
        foreach (Category::cursor() as $category){
            for ($i=0; $i<20; $i++){
                DB::table('articles')->insert([
                    [
                        'image' => Str::random(16),
                        'video' => Str::random(16),
                        'video_type' => rand(1,2),
                        'category_id' => $category->id,
                        'user_id' => $user ? $user->id : null,
                        'visit_counts' => rand(1,10000),
                        'created_at' => now(),
                    ],
                ]);
            }

        }
    }
}
