Please suggestions on how to go about this will be really appreciated. Am building a quiz app, where users can selected subject and based on the subject selected set of questions (one question per page) are displayed and upon completion and submit the user is graded based on the number of questions right and wrong.
The questions are coming from a database table with 4 possible options and also the correct option is store in the database .
My challenge now is displaying the question and allowing for next and previous questions.
I tried using Laravel pagination but it not working because am using POST data to populate the query which the pagination is using, so it not working when the next button is clicked.
You need to have two controllers, one that handles the question displaying and one that handles that answer. Once the user submits an answer, the answer gets recorded in session or database, and the controller redirects to a new (random?) question until X number of questions are answered. You can then use a third controller to show the score display.
@mezie are you trying to use Laravel's pagination? If so, you could do something like this..
public function getAnswer(Request $request)
{
// Get & save the answer
$nextPage = $request->input('page') + 1;
return redirect()->route('question.show', ['page' => $nextPage]);
}
@mezie where do you post the questions? You need to also have a hidden input field named page with the current page id in your form, so you can keep track of the current page and send the user to the next page when they submit an answer. Like I showed earlier.
Ok, it seems you've just started and I've already explained to you what the steps are, so just keep building on that.. It's not that complicated, give it a shot :)
You need a show question controller method with ->paginate(1) to get one question at the time, you also need to send the current page number to the view.
You need to add <input type="hidden" name="page" value="{{ $page }}"> to your view form to keep track of the current page
You need a submit answer controller method to handle the answer, like save it in session or database and redirect to next page
Once all questions are answered, your submit answer controller should redirect to a score page where you show the user how many questions they answered correctly
You need to figure out what your needs are and how you want your application to work, and then decide what works best to accomplish that.
You could for example save all questions/answers in the session and when everything is done save everything to the database all at once or save each question/answer to the database after each answer.