5.1 空值字段查询怎么写
查询字段 name,如果请求name为空值,以下写法无效,求答案!
$name = $request->input("name");
$email = $request->input("email");
$sql =DB::table('users')->where(function (加粗文字$query) {
if(isset($name)){
$query->where('name', 2);
}
})->toSql();
$name = $request->input("name");
$email = $request->input("email");
$sql =DB::table('users')->where(function (加粗文字$query) {
if(isset($name)){
$query->where('name', 2);
}
})->toSql();
1 个回复
yuzhahui
赞同来自:
$user =DB::table('users')->where(function ($query) use ($request){
$name = $request->input("name");
$email = $request->input("email");
if(!empty(Trim($name))){
$query->where('name','like','%'.$name.'%');
}
if(!empty(Trim($email))){
$query->where('email','like','%'.$email.'%');
}
})->paginate($rp);