gpt4 book ai didi

php - 如何在用户可以创建报告之间添加一些时间?

转载 作者:太空宇宙 更新时间:2023-11-04 05:52:43 24 4
gpt4 key购买 nike

我需要设置一个计时器,比如用户可以进行报告之间的 5 分钟,这可能吗?这是我尝试过的方法,但没有成功。在我的表中,我有 created_at 列,如果报告是在最近 5 分钟内创建的,我想显示一条消息:Report created within the last 5 minutes

这是我的 Controller

public function careerReportCareerSolution(requ $request)
{
$reportExists = \App\Reports::where('user_id', $request['user_id'])
->whereDate('created_at', '>', Carbon::now()->subMinutes(5)->toDateTimeString())
->exists();

if($reportExists) {
// report has been created within 5 minutes
return Redirect::back()->withErrors(['error', 'Report created within the last 5 minutes']);
}

$report = \App\Reports::create([
'user_id' => $request['user_id'],
'username' => $request['username'],
'user_id_posted' => $request['user_id_posted'],
'username_posted' => $request['username_posted'],
'career_solution_id' =>$request['career_solution_id'],
'subject' =>$request['subject'],
'why_reporting' =>$request['why_reporting'],
'why_reporting_message' =>$request['why_reporting_message'],
'additional_message' =>$request['additional_message'],
'comment' =>$request['comment'],
'comment_user' =>$request['comment_user'],
'comment_id' =>$request['comment_id'],
]);
$id = $request['career_solution_id']; // looks like this is the ID you ar looking for

$career = CareerSolution::findOrfail($id);
$career->active = $request['active'];
$career->save();

if ($report != "") {
flash('Career solution report submited', 'success');
} else {
flash('Career solution report', 'warning');
}

return Redirect::back();
}

最佳答案

那里我认为你应该像这样使用它可能是 Eloquent 查询中的错误。尝试这样的事情

$lastReport = \App\Reports::where('user_id', $request['user_id'])
->orderBy('id', 'desc')
->first();
$lastReportOn = time() - \Carbon\Carbon::parse($lastReport->created_at)->timestamp;

if($lastReportOn < 300 ) {
// report has been created within 5 minutes
return Redirect::back()->withErrors(['error', 'Report created within the last 5 minutes']);
}

这样的事情可以帮助你,如果还没有解决,请回复我。

关于php - 如何在用户可以创建报告之间添加一些时间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58117181/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com