I want to change value of data if countdown timer has passed in Laravel 6

Viewed 674

I'm making a Queueing system and I want the called queue number to go back to last queue in case the user doesn't show for the transaction for a given period of time. Please help me how to do this.

This is my function for calling a queue:

public function callqueue(Request $request)
{
    $request->validate([
        'called'  => ['max:255'],
        'counter' => ['max:255']
    ]);

    $dept = Auth::user()->department;
    $call = Queue::where([
            ['department',$dept],
            ['called', 'no']
        ])
        ->whereDate('created_at', Carbon::today())
        ->orderBy('id', 'asc')
        ->first();

    if ( ! is_null($call)) {
        $call->update([
            'called'  => $request->called,
            'counter' => $request->counter
        ]);
        $call->save();
        event(new NewQueue($call));
        return redirect('admin')->withStatus(__('Queue has been called.'));
    } else {
        return redirect('admin')->withStatus(__('No available queue for calling.'));
    }
}
1 Answers

I have created similar queue system, do comment if you need any modification

I want the called queue number to go back to last queue in case the user doesn't show for the transaction for a given period of time.

On queue table put 2 timestamps last_updated_at and next_update_at

Pick the first in queue ordering by nexy_update_at

$call=Queue::...
    ->where('next_update_at', '>', Carbon::now()->timestamp) # I recommend to use timestamp not datetime
    ->orderBy('next_update_at', 'asc')
    ->first();

if ($call) {
// do the task
}

Now whenever person shows up in website or anything you wish, just pick his queue task and update the next_update_at

Queue::where('user_id', ...)
    ->...
    ->update(['next_update_at', now()->timestamp]);
Related