查询生成器。同时使用 Where() 和 With() 方法
Query builder. Simultaneously Where() and With() methods
HTML 表单包含多个我将它们发送到服务器
$min = $request->input('min');
$max = $request->input('max');
$sort = $request->input('sort');
有时输入的值为空,因此我使用查询生成器:
$q = DB::table('adverts');
if ($request->has('max') && $request->input('max') != ""){
$q->where('price', "<" , $max)->orderBy($col, $way);
}
但是如果我添加 ->with('images') 我得到一个错误 Call to undefined method Illuminate\Database\Query\Builder::with()
if ($request->has('max') && $request->input('max') != ""){
$q->where('price', "<" , $max)->with('images')->orderBy($col, $way);
}
HTML 表单包含多个我将它们发送到服务器
$min = $request->input('min');
$max = $request->input('max');
$sort = $request->input('sort');
有时输入的值为空,因此我使用查询生成器:
$q = DB::table('adverts');
if ($request->has('max') && $request->input('max') != ""){
$q->where('price', "<" , $max)->orderBy($col, $way);
}
但是如果我添加 ->with('images') 我得到一个错误 Call to undefined method Illuminate\Database\Query\Builder::with()
if ($request->has('max') && $request->input('max') != ""){
$q->where('price', "<" , $max)->with('images')->orderBy($col, $way);
}