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