Hao*_*ung 1 get-request laravel undefined-variable
我的http:// localhost:8888 / VGL / public / category / 18?sty = 3
当dd($request->sty);等于3
但是我把$request->sty在whereHas为
未定义的变量:请求
public function show(Request $request, $id)
{
$products = Product::with('features')
->whereHas('features', function ($q) {
return $q->where('id', $request->sty);
})
->where('category_id',17)
->get();
}
Run Code Online (Sandbox Code Playgroud)
尝试这个
如果您想在中使用任何变量,where closure则必须在use($variable)
public function show(Request $request, $id)
{
$products = Product::with('features')
->whereHas('features', function ($q) use($request) {
return $q->where('id', $request->sty);
})
->where('category_id',17)
->get();
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
270 次 |
| 最近记录: |