Php null在不是表laravel 5.8中的数据时,返回总和为0的整数

Php null在不是表laravel 5.8中的数据时,返回总和为0的整数,php,mysql,sql,laravel,eloquent,Php,Mysql,Sql,Laravel,Eloquent,我的查询 $summary['total_cash'] = DB::table('wallets') ->select(DB::raw('SUM(amount) as total_cash')) ->where('payment_details','affiliate product purchase commission')

我的查询

 $summary['total_cash'] = DB::table('wallets')
                                  ->select(DB::raw('SUM(amount) as total_cash'))
                                  ->where('payment_details','affiliate product purchase commission')
                                  ->where('user_id',$group_id)
                                  ->first()->total_cash;
我犯了一个错误

这些表中都没有可用的数据

我想返回0

如果有任何打字错误,请忘记


谢谢

如果数据库中的金额字段默认为空,请尝试此操作

$summary['total_cash'] = DB::table('wallets')
                         ->select(DB::raw('coalesce(SUM(amount),0) as total_cash'))
                         ->where('payment_details','affiliate product purchase commission')
                         ->where('user_id',$group_id)
                         ->first()->total_cash

请出示您想要退货的东西。您的查询返回多个列,因此
0
没有意义。我认为你真的应该在应用程序中处理这个问题。这个标题似乎与你遇到的代码和错误没有任何关系posted@iainn,查询已编辑,请立即查看此
其中('payment_details','affiliate product purchase commission')
错误。
payment\u details
是否必须具有这4个值之一?如果是,请使用
,其中
方法。@AkhtarMunir是,但我已更改为0