Hi!
Background info: I'm trying to build a small quiz app. Where admin and mods can compose questions under different subjects, with four (4) options, one of them is correct. And then users should be able to participate in a quiz (but thats will be my next thread after this).
So far, I have two (2) tables answers and questions.
First off, answers:
Schema::create('answers', function (Blueprint $table) {
$table->increments('id');
$table->text('content');
$table->boolean('correct');
$table->integer('question_id');
$table->timestamps();
});
Then questions:
Schema::create('questions', function (Blueprint $table) {
$table->increments('id');
$table->integer('subject');
$table->text('question');
$table->text('question_source');
$table->string('image_url')->nullable();
$table->timestamps();
});
I have a QuestionsController where i save the question at this point, but how should i do to save the answers as well?
public function store(Request $request, Question $question){
$this->validate($request, [
'subject' => 'required',
'question' => 'required|min:10',
'question_source' => 'required|min:10',
'answer.0' => 'required',
'answer.1' => 'required',
'answer.2' => 'required',
'answer.3' => 'required',
'correct' => 'required|in:1,2,3,4',
'file' => 'mimes:jpeg,jpg,png']);
$question = new Question;
$question = Question::create($request->all());
$request->session()->flash('message', 'Question was successfully added!');
return back();
}
}
So have can i save values from one form, into two tables?