ErrorException:未定义的变量:文件中的请求 [英] ErrorException: Undefined variable: request in file

查看:35
本文介绍了ErrorException:未定义的变量:文件中的请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

错误 ErrorException:未定义的变量:文件中的请求始终出现,即使我已如下定义

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

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) {
                    $query->where('log', 'like', '%' . $request->log . '%');
                })
        ->get();

        return view('front.postlog2')
            ->with('postlocations', $postlocations)
        ;
    }

推荐答案

您将必须使用 $ request 变量在 whereHas 函数中,就像我所展示的

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

这篇关于ErrorException:未定义的变量:文件中的请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆