如何通过使用Eloquent模型来转义查询? [英] How to escape a query using an Eloquent model select?
本文介绍了如何通过使用Eloquent模型来转义查询?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
DB :: select
将第二个参数作为在此描述,但 Eloquent :: select
不。
DB::select
takes a second parameter as described here, but Eloquent::select
does not.
这是我的查询:
Feature::where('company_id', Auth::user()->company_id)
->select('id','name',DB::raw("exists(select * from vehicle_features vf where vf.vehicle_id=$id and vf.feature_id=feature.id) as `checked`"))
->orderBy('name')->get(),
如何确保 $ id
正确转义?
推荐答案
使用 DB :: getPdo() - > quote($ id) code>
。
->select(
'id',
'name',
DB::raw(
"exists(select * from vehicle_features vf where vf.vehicle_id="
. DB::getPdo()->quote($id)
. " and vf.feature_id=feature.id) as `checked`"
)
)
这篇关于如何通过使用Eloquent模型来转义查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文