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

时间:2019-09-25 13:35:22

标签: php laravel

我的函数出现此错误。我试图在user_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 个答案:

答案 0 :(得分:1)

像这样使用Carbon门面:

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