<?php

use Illuminate\Database\Seeder;
use App\User;
use App\Module;
use Illuminate\Support\Facades\DB;

class UserModuleSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        $user= User::first();
        $data= [];
        foreach (Module::cursor() as $key => $module) {
            $data[]= ['user_id' => $user ? $user->id : null, 'module_id' => $module->id];
        }
        DB::table('user_modules')->insert($data);

    }
}
