![](/img/trans.png)
[英]Call to undefined function App\Http\Controllers\now() in laravel
[英]Call to undefined function App\Http\Controllers\now()
我的 function 上有這個錯誤。我正在嘗試在 user_id 提交報告之間添加一個 5 分鍾的計時器。但由於某些原因,我有這個錯誤。
這是我的 controller
public function careerReportCareerSolution(requ $request)
{
$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'],
]);
if($report != ""){
flash('Career solution report submited', 'success');
}else{
flash('Career solution report', 'warning');
}
$reportExists = \App\Reports::where('user_id', $request['user_id'])
->whereDate('created_at', '>', 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']);
}
return Redirect::back();
}
像這樣使用Carbon
外觀:
$reportExists = \App\Reports::where('user_id', $request['user_id'])
->whereDate('created_at', '>', Carbon::now()
->subMinutes(5)->toDateTimeString())
->exists();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.