ErrorException: Undefined variable: request in file

前端 未结 1 992
遥遥无期
遥遥无期 2021-01-28 06:35

Error ErrorException: Undefined variable: request in file always appears, even though I have defined it as below

public function postlog_show(Re         


        
相关标签:
1条回答
  • 2021-01-28 06:55

    you will have to use $request variable in whereHas function, like I've shown

    public function postlog_show(Request $request)
    {
        $log = $request->log;
        $userlocation = Auth::user()->location;
        $postlocations = Postlocation::orderBy('id', 'DESC')->where('location', $userlocation)
                ->whereHas('postlognya', function (Builder $query) use($request){
                    $query->where('log', 'like', '%' . $request->log . '%');
                })
        ->get();
    
        return view('front.postlog2')
            ->with('postlocations', $postlocations)
        ;
    }
    
    0 讨论(0)
提交回复
热议问题