我正在使用 laravel eloquent 从多个列中获取数据。我正在使用数组从多个列中获取数据。为简单起见,我显示了两列的数据。
这是我的数据库表,其中包含callee_number
和caller_number
:
这是我使用数组来获取列的代码:
$paramArray = $params->all();
$Caller_number = "";
$Callee_number = "";
if (isset($paramArray['Caller_number']) && $paramArray['Caller_number'] != '') {
$Caller_number = $params->input('Caller_number');
}
if (isset($paramArray['Callee_number']) && $paramArray['Callee_number'] != '') {
$Callee_number = $params->input('Callee_number');
}
if($Caller_number!=null){
$querypart[] = "caller_number=$Caller_number";
}
if($Callee_number!=null){
$querypart[] = "callee_number=$Callee_number";
}
$FinalQueryPart = '';
if (!empty($querypart)) {
$Seprator = "";
foreach ($querypart as $querypartValue) {
$FinalQueryPart .= $Seprator . $querypartValue;
$Seprator = " AND ";
}
}
$FinalQueryPart = trim($FinalQueryPart); //Output: "caller_number=783 AND callee_number=77"
但是,在上面的代码之后运行以下代码后,我收到错误:
$gets = Tbcdrnew::where(function ($query) use ($FinalQueryPart) {
$query->MIN('uniqueid')->where($FinalQueryPart)
->from('cdrnew');
})->groupBy('uniqueid')->orderBy('Start_Date','DESC')->get();
错误如下:
Illuminate\Database\QueryException: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'caller_number=783 AND callee_number=77' in 'where clause' (SQL: select * from `cdrnew` where (`caller_number=783 AND callee_number=77` is null) group by `uniqueid`
不明白我的代码中有什么问题。有人可以纠正我吗?
万千封印
杨魅力