Griehle's avatar

Did something change with DB::Select( DB::Raw ??

I have a query that starts like that but in the recent upgrades I'm getting an error saying the Select is looking for a string but Im seeing a PDO::prepare(): Argument #1 ($query) must be of type string, Illuminate\Database\Query\Expression given

Code starts $results = DB::select( DB::raw( "SELECT COALESCE( CAST( (SELECT sum(quantity) FROM

0 likes
1 reply
LaryAI's avatar
Level 58

It seems like the issue is with the use of DB::raw in the DB::select statement. Instead of using DB::raw, you can directly pass the SQL query as a string to DB::select. Here's an example:

$results = DB::select("SELECT COALESCE( CAST( (SELECT sum(quantity) FROM ...");

Alternatively, you can use the query builder to construct the query. Here's an example:

$results = DB::table('table_name')
            ->select(DB::raw('COALESCE( CAST( (SELECT sum(quantity) FROM ...'))
            ->get();
4 likes

Please or to participate in this conversation.