当前位置: 首页 > 知识库问答 >
问题:

调用未定义的函数App\Http\Controllers\now()

苏嘉歆
2023-03-14

我的函数出现此错误。我正在尝试在按用户id提交报告之间添加5分钟计时器。但由于某些原因,我出现此错误。

这是我的控制器

 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();


    }

共有1个答案

梁丘德寿
2023-03-14

使用这样的Carbon门面:

$reportExists = \App\Reports::where('user_id', $request['user_id'])
                ->whereDate('created_at', '>', Carbon::now()
                ->subMinutes(5)->toDateTimeString())
                ->exists();
 类似资料: