This repository has been archived on 2021-01-24. You can view files and clone it, but cannot push or open issues or pull requests.
laravel-elearning/database/seeds/DatabaseSeeder.php

86 lines
3.6 KiB
PHP

<?php
use Illuminate\Database\Seeder;
class DatabaseSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
factory(App\Group::class)->create([
'name' => 'WalbeckDK'
])->each(function($g) {
$g->users()->save(factory(App\User::class)->create([
'name' => 'Magnus Walbeck',
'email' => 'admin@walbeck.dk',
'password' => bcrypt('magnus'),
'group_id' => 1,
'access_level' => 3,
]));
$g->users()->save(factory(App\User::class)->create([
'name' => 'Mod',
'email' => 'mod@walbeck.dk',
'password' => bcrypt('magnus'),
'group_id' => 1,
'access_level' => 2,
]));
$g->tests()->save(factory(App\Test::class)->make());
$g->tests()->save(factory(App\Test::class)->make());
$g->tests()->save(factory(App\Test::class)->make());
$g->tests()->save(factory(App\Test::class)->make());
$g->tests()->save(factory(App\Test::class)->make());
});
factory(App\Group::class, 5)->create()->each(function($g) {
$g->users()->save(factory(App\User::class)->make());
$g->users()->save(factory(App\User::class)->make());
$g->users()->save(factory(App\User::class)->make());
$g->users()->save(factory(App\User::class)->make());
$g->users()->save(factory(App\User::class)->make());
$g->tests()->save(factory(App\Test::class)->make());
$g->tests()->save(factory(App\Test::class)->make());
$g->tests()->save(factory(App\Test::class)->make());
$g->tests()->save(factory(App\Test::class)->make());
$g->tests()->save(factory(App\Test::class)->make());
});
$tests = App\Test::all();
foreach ($tests as $test) {
$test->questions()->save(factory(App\Question::class, "single")->make());
$test->questions()->save(factory(App\Question::class, "single")->make());
$test->questions()->save(factory(App\Question::class, "single")->make());
$test->questions()->save(factory(App\Question::class, "double")->make());
$test->questions()->save(factory(App\Question::class, "double")->make());
$test->questions()->save(factory(App\Question::class, "double")->make());
}
$questions = App\Question::all();
foreach ($questions as $question) {
if ($question->multiple_answers_question) {
$question->options()->save(factory(App\Option::class)->make());
$question->options()->save(factory(App\Option::class)->make());
$question->options()->save(factory(App\Option::class)->make([
'option' => "This is the correct answer",
'correct_answer' => 1,
]));
$question->options()->save(factory(App\Option::class)->make([
'option' => "This is the correct answer",
'correct_answer' => 1,
]));
} else {
$question->options()->save(factory(App\Option::class)->make());
$question->options()->save(factory(App\Option::class)->make());
$question->options()->save(factory(App\Option::class)->make());
$question->options()->save(factory(App\Option::class)->make([
'option' => "This is the correct answer",
'correct_answer' => 1,
]));
}
}
}
}