我正在尝试从特定月份的表中获取金额的总和,但出现此错误:
htmlspecialchars()期望参数1为字符串,指定对象
'currentmonthbilling'=>对象(生成器)
表格名称为帐单
我已编写查询
$currentMonth = date('m');
$currentmonthbilling = DB::table("billings")
->select(DB::raw("SUM(amount)"))
->whereRaw('MONTH(created_at) = ?',[$currentMonth]);
我希望获得当月每个人支付的总金额
答案 0 :(得分:2)
要获取查询结果,您必须在末尾添加get()
。
喜欢:
$currentMonth = date('m');
$currentmonthbilling = DB::table("billings")
->select(DB::raw("SUM(amount) as total"))
->whereRaw('MONTH(created_at) = ?',[$currentMonth])
->get();
答案 1 :(得分:0)
使用sum(DB::raw('amount'))
代替select(DB::raw("SUM(amount)"))
$currentMonth = date('m');
$currentmonthbilling = DB::table("billings")
->sum(DB::raw('amount'))
->whereRaw('MONTH(created_at) = ?',[$currentMonth])->get();