added seed for multi answer questions and options
This commit is contained in:
parent
8afccdc7f5
commit
634a43b93d
2 changed files with 41 additions and 39 deletions
database
|
@ -13,7 +13,6 @@
|
|||
|
||||
$factory->define(App\User::class, function (Faker\Generator $faker) {
|
||||
static $password;
|
||||
|
||||
return [
|
||||
'name' => $faker->name,
|
||||
'email' => $faker->safeEmail,
|
||||
|
@ -23,14 +22,12 @@ $factory->define(App\User::class, function (Faker\Generator $faker) {
|
|||
});
|
||||
|
||||
$factory->define(App\Group::class, function (Faker\Generator $faker) {
|
||||
|
||||
return [
|
||||
'name' => $faker->company
|
||||
];
|
||||
});
|
||||
|
||||
$factory->define(App\Test::class, function (Faker\Generator $faker) {
|
||||
|
||||
return [
|
||||
'title' => $faker->sentence(3, true),
|
||||
'question_count' => 6,
|
||||
|
@ -39,21 +36,29 @@ $factory->define(App\Test::class, function (Faker\Generator $faker) {
|
|||
];
|
||||
});
|
||||
|
||||
$factory->define(App\Question::class, function (Faker\Generator $faker) {
|
||||
|
||||
$factory->defineAs(App\Question::class, "single", function (Faker\Generator $faker) {
|
||||
return [
|
||||
'title' => $faker->sentence(6, true),
|
||||
'question' => $faker->paragraph(3, true),
|
||||
'question_type' => "radio",
|
||||
'correct_answers' => 1,
|
||||
'multiple_answers_question' => 0
|
||||
'multiple_answers_question' => 0,
|
||||
];
|
||||
});
|
||||
|
||||
$factory->defineAs(App\Question::class, "double", function (Faker\Generator $faker) {
|
||||
return [
|
||||
'title' => $faker->sentence(6, true),
|
||||
'question' => $faker->paragraph(3, true),
|
||||
'question_type' => "checkbox",
|
||||
'correct_answers' => 2,
|
||||
'multiple_answers_question' => 1,
|
||||
];
|
||||
});
|
||||
|
||||
$factory->define(App\Option::class, function (Faker\Generator $faker) {
|
||||
|
||||
return [
|
||||
'option' => $faker->sentence(4, true),
|
||||
'correct_answer' => 0
|
||||
'correct_answer' => 0,
|
||||
];
|
||||
});
|
||||
});
|
|
@ -51,39 +51,36 @@ class DatabaseSeeder extends Seeder
|
|||
|
||||
$tests = App\Test::all();
|
||||
foreach ($tests as $test) {
|
||||
$test->questions()->save(factory(App\Question::class)->make());
|
||||
$test->questions()->save(factory(App\Question::class)->make());
|
||||
$test->questions()->save(factory(App\Question::class)->make());
|
||||
$test->questions()->save(factory(App\Question::class)->make());
|
||||
$test->questions()->save(factory(App\Question::class)->make());
|
||||
$test->questions()->save(factory(App\Question::class)->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, "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) {
|
||||
$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,
|
||||
]));
|
||||
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,
|
||||
]));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
$t->questions()->save(factory(App\Question::class, 6)->create()->each(function($q) {
|
||||
DB::table('options')->insert([
|
||||
'question_id' => $q->id,
|
||||
'option' => "true",
|
||||
'correct_answer' => 1,
|
||||
]);
|
||||
DB::table('options')->insert([
|
||||
'question_id' => $q->id,
|
||||
'option' => "false",
|
||||
'correct_answer' => 0,
|
||||
]);
|
||||
}));
|
||||
*/
|
||||
}
|
Reference in a new issue