我使用雄辩的php作为orm,并为我的web应用程序实现查询生成器。
通常,当代码看起来像这样时,它会工作。
$builder = Area::query()->limit(30);
if ($subDistrictCode = $request->getParam('sub_district_code')) {
$builder->where('sub_district_code', $subDistrictCode);
}
if ($districtCode = $request->getParam('district_code')) {
$builder->where('district_code', $districtCode);
}
$areasCount = $builder->count();
if ($limit = $request->getParam('length')) {
$builder->limit($limit);
}
if ($offset = $request->getParam('start')) {
$builder->offset($offset);
}
$areas = $builder->orderBy('province','ASC')->get();
但当我使用对象的属性时,我得到了以下错误:
调用未定义的方法erdkk\models\areas::getidattribute()
代码如下所示。
$builder = Area::query()->limit(30);
if ($subDistrictCode = $request->getParam('sub_district_code')) {
$builder->where('sub_district_code', $subDistrictCode['id']);
}
if ($districtCode = $request->getParam('district_code')) {
$builder->where('district_code', $districtCode);
}
$areasCount = $builder->count();
if ($limit = $request->getParam('length')) {
$builder->limit($limit);
}
if ($offset = $request->getParam('start')) {
$builder->offset($offset);
}
$areas = $builder->orderBy('province','ASC')->get();
暂无答案!
目前还没有任何答案,快来回答吧!