[英]ErrorException: Undefined variable: request in file
错误ErrorException:未定义的变量:文件中的请求总是出现,即使我已将其定义如下
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)
;
}
你将不得不在whereHas
函数中use
$request
变量,就像我展示的那样
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)
;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.