Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Asser90's avatar

Show one question per page?

I'm currently in the making of a quiz system using laravel.

I've done most the work allready however i cant seem to figure out how i get laravel to display only one question pr page? - I know how to show them all through a foreach loop and i have bound them all through relationships.

I have one question which has up to 4 postulates which you can answer yes or no to.

Its meant that when you click the next question button it will save your inputs in case you loose internet connection or just want to continue later on.

Would anyone know how to achieve this?

You dont have to write bunch of code i just need to be pointed in the right direction.

0 likes
10 replies
EmilMoe's avatar

Since you want the offline compatibility I suggest you make it in Javascript and a backend API. You could take a look at the VueJS lessons on this website.

In this way you save the current question and when they answer your API respond with the next question. You can reference the questions with UID (Unique Identifier) if you don't want anyone to be able to guess the number of the next question.

But before it makes sense to explain in detail you should know about Javascript and AJAX. I recommend VueJS and Vue-Resource, but that's completely up to you if you prefer something else instead.

Asser90's avatar

Thanks for your input EmilMoe.

Ill look into some vueJS and Vue-Resource. My js is limited to mostly using jquery, so i might have to learn some new stuff here ;)

My project does now however seem harder than i first thought.

EmilMoe's avatar

You can do it without Javascript, but I think in the long run you will be happy to benefit from it here.

My recommendation to you is to watch the entire serie about Vue (the 1.xx one, not the one from before version 1). Then you can decide if it feels right for you after. It's a day or half you have to invest, but might pay off.

For me was jQuery always a mess after a while and Angular seem bloated with unnecessary stuff, where I found Vue to be a more simple approach that is closer to how I work in PHP.

I wrote an article about how to get started with Vue in Laravel, but yeah, you will see it all in the videos if you follow them. https://hashnode.com/post/vuejs-with-keen-ui-cinqcbns701yixt53xnarmcg4

Asser90's avatar

Allright thanks again.

I will have a look at the vue series.

Can i ask you what you mean by Backend API, just to be sure we are thinking of the same?

EmilMoe's avatar

You call an URL with an AJAX request that responds with a string or JSON object.

There's a short guideline here to do RESTful https://en.wikipedia.org/wiki/Representational_state_transfer#Relationship_between_URI_and_HTTP_Methods

But it is basically that:

To get the question: GET yourapp/question/_id_
To answer the question: POST yourapp/question/_id_

Maybe to get the next question: GET yourapp/question/_id_/next

Hope it makes sense and that I'm not putting too much work on you. My Youtube isn't working for some reason, but there are some explanations https://www.youtube.com/watch?v=7YcW25PHnAA

But again, it's not rocket science just an URL that responds some data.

Asser90's avatar

I think i got get what you're saying.

I'll have a look at it.

Asser90's avatar

Btw. i do not need any offline compability.

I do however need a way so that when you click on next it saves the answers to the database as you go through the questions. So if you loose internet in the middle of a question its only that one and the ones ahead that you "havent" answered.

So all the allready answered will stay answered ;)

Does that make sense ?

EmilMoe's avatar

That is sort of offline compatibility. I think you can store it in Web Storage, but someone else might be better at explaining this issue.

Asser90's avatar

Right now im storing in mysql, but ill probably figure it out. Thanks anyway.

Please or to participate in this conversation.