查询倒数计时器的数据库

I'm working with Laravel and I have a database which contains two tables: in the first table there is a column with an integer field that I want to work like a timer, in the second table I store when an user submit a form and there is a timestamp with the time of the submit. I would to prevent the user to submit the same form before the expiry of the time specified by the field in the first table. How can I do that ?

Here is the code in the controller:

public function getShow($id = null){
  if ( ! is_null($id)){
     $submitted = Actionshistory::where('action_id','=',$id)->first()->created_at;
     $minutes = Actions::where('id','=',$id)->pluck('time_need'); // time need between submit two same form.
     $passed = Carbon::createFromTimeStamp($submitted)->diffInMinutes(Carbon::now('Europe/Rome'));
        if ($submitted && $passed >= $minutes)
        {
         // Other queries and success message
        }
         // Error message
        }
         // error message for id
}

I need to use Carbon::now('Europe/Rome').

Thanks.

Without seeing your code, there's no specific answer. Here's something to get you started:

$submitted = Actionshistory::where('action_id', $id)->first()->created_at;
$interval  = Actions::where('id','=',$id)->pluck('time_need');

if ($submitted->diffInMinutes(Carbon::now()) < $interval)
{
    // throw your error or whatnot
}

Create a hidden input which will contain the time the form was served.

Form::hidden('time_served', Carbon::now());

You will need to use ajax on the onsubmit event for your form to check that the time is valid and return true or false which will either stop or let the form submission proceed.

The javascript would look something like...

$(document).ready(function() {
    $('#MyForm').on('submit', function(e) {
        $.getJSON('some/route', {}, function(data, textStatus) {
            if(data.success) {
                return true;
            } else {
                alert(data.message);
                return false;
            }
        });
    });
});

Now your some/route route which is returning the json would look similar to...

Route::get('some/route', function()
{
    $time_served = Input::get('time_served');
    $difference = Carbon::createFromTimeStamp($time_served)->diffInSeconds(Carbon::now());
    $seconds_allowed = Config::get('timers.seconds');  // However you get your "timer"

    if($seconds_allowed > $difference) {
        return Response::json(array('success' => true, 'message' => 'Time requirement met.'));
    } else {
        return Response::json(array('success' => false, 'message' => 'Time requirement not met.'));
    }

});