In Laravel 4, I want to protect some complex database queries from SQL injection. These queries use a combination of the query builder and DB::raw(). Here is a simplified ex
I discovered the query builder has a method called setBindings() that can be useful in this instance:
$field = 'email'; $id = 1; $user = DB::table('users')->select(DB::raw(":field as foo")) ->addSelect('email') ->whereId(DB::raw(":id")) ->setBindings(['field' => $field, 'id' => $id]) ->get();