DB::select
takes a second parameter as described here, but Eloquent::select
does not.
Here's my query:
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(),
How can I ensure $id
is escaped properly?
You may use PDO or easier manually add binding to the Query:
edit: as stated in the comments below, bindings are bugged and methods order does matter, so the above will work as expected.
Use
DB::getPdo()->quote($id)
.