我在使用ajax进行选择时遇到问题:
“ SQLSTATE [42S22]:找不到列:1054'where子句'中的未知列'full_name'(SQL:从驱动器中将count(*)汇总为像%%▶这样的full_name的驱动程序”
public function drivers(Request $request)
{
$q = $request->get('q');
return Driver::select("id", "first_name", "last_name"
,DB::raw("CONCAT(first_name,' ',last_name) as full_name"))
->where('full_name', 'like', "%$q%")->paginate(null, ['id', 'full_name as text']);
}
我不知道问题出在哪里,有什么可能的解决办法?
谢谢
答案 0 :(得分:0)
您不能在where
子句中使用虚拟列或别名。因此,请尝试以下方法:
public function drivers(Request $request)
{
$q = $request->get('q');
return Driver::select("id", "first_name", "last_name",
DB::raw("CONCAT(first_name,' ',last_name) as full_name"))
->having('full_name', 'like', "%$q%")->simplePaginate(10);
}
答案 1 :(得分:0)
为什么不这样尝试
return Driver
::select("id", "first_name", "last_name",DB::raw("CONCAT(first_name,' ',last_name) as full_name"))
->whereRaw('full_name like %?%', [$q])
->paginate(null, ['id', 'full_name as text']);