I’m writing some complex queries using Eloquent and I need to escape some queries using raw. Examples from Laravel are using using the following construct to escape a query using raw();
\DB::raw();
However, for the life of me I can’t seem to figure out the correct namespace/path to access a proper raw() function (given that the above is for a Laravel-specific context). Can someone please point me in the right direction?
To clarify, I know how to do a raw where clause or an entire raw query, but I have no idea how to escape a single where parameter using raw(). For reference, want to escape the $uid parameter in the following query (because Eloquent insists on using the value of $uid as a column name):
$wallets = self::where('sequence', '=', $sequence)->where('interval', '=', $minutes)
->leftJoin('wallet', 'wallet_stats.wallet_id', '=', 'wallet.id')
->leftJoin('balance', function($join) use ($uid)
{
$join->on('balance.wallet_id', '=', 'wallet_stats.wallet_id')
->on('balance.user_id', '=', $uid);
})
->orderBy($sort, 'ASC')->get(['symbol', 'name', 'volume', 'start_price', 'end_price']);
Thanks for any pointers.