我正在使用Laravel Eloquent。我需要一个列名称为camel-case。查询如下所示:
IDProofDetails::select('idproof_details.idproof_id as IDNumber', 'idproof_types.lcode_id_proof_name as idProofType',
DB::raw("ENCODE(CONVERT_TO(photo, 'UTF-8'), 'base64') as PhotoImage"))
->leftJoin('idproof_types', 'idproof_types.id', '=', 'idproof_details.id_proof_type_id')
->get();
结果如下所示:
[
"IDNumber" => "df23redf",
"idProofType" => "AADHAR",
"photoimage" => null
]
其他2列工作正常,但原始查询PhotoImage
内的列正在photoimage
。有没有选择让它成为驼峰式的?
答案 0 :(得分:2)
“PhotoImage”的别名可以通过DB::raw('"PhotoImage"')
现在试试这个
IDProofDetails::select('idproof_details.idproof_id as IDNumber', 'idproof_types.lcode_id_proof_name as idProofType',
DB::raw("ENCODE(CONVERT_TO(photo, 'UTF-8'), 'base64') as ".DB::raw('"photoImage"')."" ))
->leftJoin('idproof_types', 'idproof_types.id', '=', 'idproof_details.id_proof_type_id')
->get();
photoImage应该是引号,否则它将作为小写。