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

kpopdz's avatar

set duration for questions of quiz

hello guys i have project about quizs i want set for each question of quiz a duration ,when student start the quiz for display next question only if press next button or if duration =0 how to do that , btw i have 4 tables users , quizs,quetions,options

0 likes
4 replies
MohammedSB's avatar
Level 1

the best solution for this is using livewire, or js countdown, with the quiz duration, and once that is reached redirect the user, and you need to create a new column in your database and name it open_until and store the quiz time

for example = now + 15 minutes.

and here is a JS code that may be helpful for you

var countDownDate = new Date("Jul 25, 2021 16:37:52").getTime();

var myfunc = setInterval(function() {
    var now = new Date().getTime();
    var timeleft = countDownDate - now;
        
    var days = Math.floor(timeleft / (1000 * 60 * 60 * 24));
    var hours = Math.floor((timeleft % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
    var minutes = Math.floor((timeleft % (1000 * 60 * 60)) / (1000 * 60));
    var seconds = Math.floor((timeleft % (1000 * 60)) / 1000);
    
    }, 1000)
``
1 like
MohammedSB's avatar

To store the duration in the database you could use

$quizDuration = Carbon::now()->addMinutes(   QUIZ DURATION IN MINUTES   );		

and in your blade update countDowwDate to

var countDownDate = new Date("{{ $quizDuration }}").getTime();

BUT YOU MUST KNOW THIS IS NOT SECURE, AS IT CAN BE MODIFIED FROM THE USE SIDE, and if you are looking for more advanced logic, use livewire

1 like

Please or to participate in this conversation.