any help with this guys ?!
How to apply this scenario in Faker Laravel 5.1
Hello every one,
iam trying to make fake data for testing the actual app without manually add every thing as i need a min of 100 question =( my app is quiz
in real demo from control panel i have a form
that have a question test + 3 text input as answer and 3 radio button for choosing the correct answer and i have other field for image and select menu
for making question factory is ok i make it
$factory->define(Ideal\Questions::class, function (Faker\Generator $faker) {
return [
'question' => $faker->sentence(5),
'image' => $faker->imageUrl(250,250),
'language_id' => Ideal\Language::all()->random()->id,
];
});
but for the answers
how to do it
as i need every 3 answer to be with same question id and also only 1 answer of these 3 should be correct
$factory->define(Ideal\Answers::class, function (Faker\Generator $faker) {
return [
'answer' => $faker->word,
'question_id' => Ideal\Questions::all()->random()->id,
'correct' => $faker->boolean(15),
];
});
as u can see this is what i made and stop how i can make it work >_< as a real life demo
who to make 3 answers with same question id and only one of them is correct
Hi there,
IMHO. Don't use the factory quite like that, and I would use a table seeder.
Anyway... Remove the question_id from the Answers factory, I would set them all to be correct => false
Do the relation like http://laravel.com/docs/master/testing#model-factories -> Adding Relations To Models
You can then get a random one from the relation to set the correct one.
http://laravel.com/api/5.1/Illuminate/Database/Eloquent/Collection.html#method_random
$randomAnswer = $quenstion->answers->random();
$randomAnswer->correct = true;
$randomAnswer->save();
Hope it helps.
Please or to participate in this conversation.