duanfa2014 2014-08-06 18:02
浏览 27

查询倒数计时器的数据库

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.

  • 写回答

2条回答 默认 最新

  • dongyi1524 2014-08-06 18:22
    关注

    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
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 MATLAB中streamslice问题
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 51单片机中C语言怎么做到下面类似的功能的函数(相关搜索:c语言)
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序